Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: revert add node gpu status #761

Merged
merged 8 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions clients/tfchain-client-go/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ type PowerStateChanged struct {
Topics []types.Hash
}

type NodeGpuStatusChanged struct {
Phase types.Phase
Node types.U32 `json:"node_id"`
GpuStatus types.Bool `json:"gpu_status"`
Topics []types.Hash
}

type EntityStored struct {
Phase types.Phase
Entity Entity `json:"entity"`
Expand Down Expand Up @@ -424,7 +417,6 @@ type EventRecords struct {
TfgridModule_NodePublicConfigStored []NodePublicConfig //nolint:stylecheck,golint
TfgridModule_PowerTargetChanged []PowerTargetChanged //nolint:stylecheck,golint
TfgridModule_PowerStateChanged []PowerStateChanged //nolint:stylecheck,golint
TfgridModule_NodeGpuStatusChanged []NodeGpuStatusChanged //nolint:stylecheck,golint

// entity events
TfgridModule_EntityStored []EntityStored //nolint:stylecheck,golint
Expand Down
52 changes: 0 additions & 52 deletions clients/tfchain-client-go/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,55 +804,3 @@ func (s *Substrate) GetDedicatedNodePrice(nodeID uint32) (uint64, error) {

return uint64(price), nil
}

func (s *Substrate) SetNodeGpuStatus(identity Identity, state bool) (hash types.Hash, err error) {
cl, meta, err := s.GetClient()
if err != nil {
return hash, err
}

c, err := types.NewCall(meta, "TfgridModule.set_node_gpu_status", state)

if err != nil {
return hash, errors.Wrap(err, "failed to create call")
}

callResponse, err := s.Call(cl, meta, identity, c)
if err != nil {
return hash, errors.Wrap(err, "failed to update node gpu status")
}

return callResponse.Hash, nil
}

func (s *Substrate) GetNodeGpuStatus(nodeId uint32) (status bool, err error) {
cl, meta, err := s.GetClient()
if err != nil {
return status, err
}

bytes, err := Encode(nodeId)
if err != nil {
return status, errors.Wrap(err, "substrate: encoding error building query arguments")
}

key, err := types.CreateStorageKey(meta, "TfgridModule", "NodeGpuStatus", bytes)
if err != nil {
return status, errors.Wrap(err, "failed to create substrate query key")
}

raw, err := cl.RPC.State.GetStorageRawLatest(key)
if err != nil {
return status, errors.Wrap(err, "failed to lookup gpu status")
}

if raw == nil || len(*raw) == 0 {
return false, nil
}

if err := Decode(*raw, &status); err != nil {
return status, errors.Wrap(err, "failed to load object")
}

return status, nil
}
28 changes: 0 additions & 28 deletions clients/tfchain-client-go/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,3 @@ func TestUptimeReportV2(t *testing.T) {
_, err = cl.UpdateNodeUptimeV2(identity, 100, uint64(time.Now().Unix()))
require.NoError(t, err)
}

func TestNodeUpdateGpuStatus(t *testing.T) {
cl := startLocalConnection(t)
defer cl.Close()

identity, err := NewIdentityFromSr25519Phrase(BobMnemonics)
require.NoError(t, err)

farmID, twinID := assertCreateFarm(t, cl)

nodeID := assertCreateNode(t, cl, farmID, twinID, identity)

// toggle true
_, err = cl.SetNodeGpuStatus(identity, true)
require.NoError(t, err)

status, err := cl.GetNodeGpuStatus(nodeID)
require.NoError(t, err)
require.Equal(t, true, status)

// toggle false
_, err = cl.SetNodeGpuStatus(identity, false)
require.NoError(t, err)

status, err = cl.GetNodeGpuStatus(nodeID)
require.NoError(t, err)
require.Equal(t, false, status)
}
16 changes: 16 additions & 0 deletions docs/architecture/0013-untrack-node-gpu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 13. Untrack GPU status on a node

Date: 2023-06-22

## Status

Accepted

## Context

See [here](https://github.com/threefoldtech/tfchain/issues/759) for more details.

## Decision

Since we don't want to store non-essential data on chain and GPU information is not of any actual value to the chain or minting, the storage map `NodeGpuStatus` (see ./0012-track-node-gpu.md) is removed from `pallet-tfgrid`.
An off chain indexer will handle a node query to fetch further detailed information about nodes GPU (number / models / memory capacity / ...).
15 changes: 0 additions & 15 deletions substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,6 @@ benchmarks! {
assert_last_event::<T>(Event::NodeUptimeReported(node_id, now, uptime).into());
}

// set_node_gpu_status
set_node_gpu_status {
let caller: T::AccountId = whitelisted_caller();
_prepare_farm_with_node::<T>(caller.clone());
let node_id = 1;
let gpu_status = true;
}: _(RawOrigin::Signed(caller), gpu_status)
verify {
assert_eq!(TfgridModule::<T>::node_gpu_status(node_id), gpu_status);
assert_last_event::<T>(Event::NodeGpuStatusChanged {
node_id,
gpu_status,
}.into());
}

// Calling the `impl_benchmark_test_suite` macro inside the `benchmarks`
// block will generate one #[test] function per benchmark
impl_benchmark_test_suite!(TfgridModule, crate::mock::new_test_ext(), crate::mock::TestRuntime)
Expand Down
45 changes: 3 additions & 42 deletions substrate-node/pallets/pallet-tfgrid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ pub mod pallet {
pub type NodePower<T: Config> =
StorageMap<_, Blake2_128Concat, u32, NodePowerType<T::BlockNumber>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn node_gpu_status)]
pub type NodeGpuStatus<T: Config> = StorageMap<_, Blake2_128Concat, u32, bool, ValueQuery>;

#[pallet::config]
pub trait Config: frame_system::Config + pallet_timestamp::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down Expand Up @@ -461,10 +457,6 @@ pub mod pallet {
node_id: u32,
power_state: PowerState<T::BlockNumber>,
},
NodeGpuStatusChanged {
node_id: u32,
gpu_status: bool,
},
}

#[pallet::error]
Expand Down Expand Up @@ -2093,16 +2085,9 @@ pub mod pallet {
Self::_report_uptime(&account_id, uptime, timestamp_hint)
}

#[pallet::call_index(39)]
#[pallet::weight(<T as Config>::WeightInfo::set_node_gpu_status())]
pub fn set_node_gpu_status(
origin: OriginFor<T>,
gpu_status: bool,
) -> DispatchResultWithPostInfo {
let account_id = ensure_signed(origin)?;

Self::_set_node_gpu_status(&account_id, gpu_status)
}
// Deprecated! Use index 40 for next extrinsic
// #[pallet::call_index(39)]
// #[pallet::weight(<T as Config>::WeightInfo::set_node_gpu_status())]
}
}

Expand Down Expand Up @@ -2139,30 +2124,6 @@ impl<T: Config> Pallet<T> {
Ok(Pays::No.into())
}

pub fn _set_node_gpu_status(
account_id: &T::AccountId,
gpu_status: bool,
) -> DispatchResultWithPostInfo {
let twin_id = TwinIdByAccountID::<T>::get(account_id).ok_or(Error::<T>::TwinNotExists)?;

ensure!(
NodeIdByTwinID::<T>::contains_key(twin_id),
Error::<T>::NodeNotExists
);
let node_id = NodeIdByTwinID::<T>::get(twin_id);

ensure!(Nodes::<T>::contains_key(node_id), Error::<T>::NodeNotExists);

NodeGpuStatus::<T>::insert(node_id, gpu_status);

Self::deposit_event(Event::NodeGpuStatusChanged {
node_id,
gpu_status,
});

Ok(Pays::No.into())
}

pub fn verify_signature(signature: [u8; 64], target: &T::AccountId, payload: &Vec<u8>) -> bool {
Self::verify_ed_signature(signature, target, payload)
|| Self::verify_sr_signature(signature, target, payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod v12;
pub mod v13;
pub mod v14;
//pub mod v15;
pub mod v16;
44 changes: 44 additions & 0 deletions substrate-node/pallets/pallet-tfgrid/src/migrations/v16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::*;
use frame_support::{
traits::{OnRuntimeUpgrade, PalletInfoAccess},
weights::Weight,
};
use log::info;
use sp_std::marker::PhantomData;

pub struct KillNodeGpuStatus<T: Config>(PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for KillNodeGpuStatus<T> {
fn on_runtime_upgrade() -> Weight {
if PalletVersion::<T>::get() == types::StorageVersion::V15Struct {
info!(" >>> Kill NodeGpuStatus storage...");

let res = frame_support::migration::clear_storage_prefix(
<Pallet<T>>::name().as_bytes(),
b"NodeGpuStatus",
b"",
None,
None,
);

log::info!(
"Cleared '{}' entries from 'NodeGpuStatus' storage prefix",
res.unique
);

if res.maybe_cursor.is_some() {
log::error!("Storage prefix 'NodeGpuStatus' is not completely cleared.");
}

// Update pallet storage version
PalletVersion::<T>::set(types::StorageVersion::V16Struct);
info!(" <<< NodeGpuStatus killing success, storage version upgraded");

// Return the weight consumed by the migration.
T::DbWeight::get().reads_writes(0, res.unique as u64 + 1)
} else {
info!(" >>> Unused TFGrid pallet V16 migration");
Weight::zero()
}
}
}
44 changes: 0 additions & 44 deletions substrate-node/pallets/pallet-tfgrid/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2320,50 +2320,6 @@ fn test_farming_policies_ordering_and_assignment() {
})
}

#[test]
fn test_set_node_gpu_status_works() {
ExternalityBuilder::build().execute_with(|| {
create_twin();
create_farm();
create_node();

assert_ok!(TfgridModule::set_node_gpu_status(
RuntimeOrigin::signed(alice()),
true,
));

let status = TfgridModule::node_gpu_status(1);
assert_eq!(status, true);

assert_ok!(TfgridModule::set_node_gpu_status(
RuntimeOrigin::signed(alice()),
false,
));

let status = TfgridModule::node_gpu_status(1);
assert_eq!(status, false);
});
}

#[test]
fn test_set_node_gpu_status_node_not_exists_or_wrong_source_fails() {
ExternalityBuilder::build().execute_with(|| {
create_twin();
create_farm();

assert_noop!(
TfgridModule::set_node_gpu_status(RuntimeOrigin::signed(alice()), true,),
Error::<TestRuntime>::NodeNotExists
);

create_node();
assert_noop!(
TfgridModule::set_node_gpu_status(RuntimeOrigin::signed(bob()), true,),
Error::<TestRuntime>::TwinNotExists
);
});
}

fn create_entity() {
let name = b"foobar".to_vec();
let country = get_country_name_input(b"Belgium");
Expand Down
3 changes: 2 additions & 1 deletion substrate-node/pallets/pallet-tfgrid/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ pub enum StorageVersion {
V13Struct,
V14Struct,
V15Struct,
V16Struct,
}

impl Default for StorageVersion {
fn default() -> StorageVersion {
StorageVersion::V14Struct
StorageVersion::V16Struct
}
}

Expand Down
Loading