From 72b5c23914d758e5cdcbdc0a0c7dc14b1b732331 Mon Sep 17 00:00:00 2001 From: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:42:00 -0500 Subject: [PATCH] Follow ACP-77 naming conventions (#3546) Signed-off-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com> Co-authored-by: Meaghan FitzGerald Co-authored-by: Stephen Buttolph --- RELEASES.md | 2 +- proto/pb/platformvm/platformvm.pb.go | 114 ++--- proto/pb/validatorstate/validator_state.pb.go | 123 ++--- proto/platformvm/platformvm.proto | 10 +- proto/validatorstate/validator_state.proto | 2 +- snow/networking/router/chain_router.go | 4 +- .../gvalidators/validator_state_client.go | 16 +- .../gvalidators/validator_state_server.go | 14 +- snow/validators/validator.go | 16 +- tests/e2e/p/l1.go | 162 +++---- .../block/executor/proposal_block_test.go | 10 +- .../block/executor/standard_block_test.go | 12 +- vms/platformvm/block/executor/verifier.go | 54 +-- .../block/executor/verifier_test.go | 82 ++-- .../block/executor/warp_verifier_test.go | 2 +- vms/platformvm/client.go | 40 +- vms/platformvm/config/config.go | 4 +- vms/platformvm/config/config_test.go | 2 +- vms/platformvm/metrics/metrics.go | 16 +- vms/platformvm/metrics/tx_metrics.go | 20 +- vms/platformvm/network/warp.go | 80 ++-- vms/platformvm/network/warp_test.go | 162 +++---- vms/platformvm/service.go | 42 +- vms/platformvm/service.md | 8 +- vms/platformvm/state/chain_time_helpers.go | 27 +- .../state/chain_time_helpers_test.go | 30 +- vms/platformvm/state/diff.go | 124 ++--- vms/platformvm/state/diff_test.go | 110 ++--- vms/platformvm/state/l1_validator.go | 437 +++++++++++++++++ vms/platformvm/state/l1_validator_test.go | 246 ++++++++++ vms/platformvm/state/mock_chain.go | 200 ++++---- vms/platformvm/state/mock_diff.go | 200 ++++---- vms/platformvm/state/mock_state.go | 212 ++++----- vms/platformvm/state/state.go | 414 ++++++++--------- vms/platformvm/state/state_test.go | 392 ++++++++-------- vms/platformvm/state/subnet_only_validator.go | 439 ------------------ .../state/subnet_only_validator_test.go | 246 ---------- vms/platformvm/txs/codec.go | 10 +- ...ubnet_tx.go => convert_subnet_to_l1_tx.go} | 20 +- ...est.go => convert_subnet_to_l1_tx_test.go} | 76 +-- ...convert_subnet_to_l1_tx_test_complex.json} | 0 ... convert_subnet_to_l1_tx_test_simple.json} | 0 ...dator_tx.go => disable_l1_validator_tx.go} | 10 +- ...est.go => disable_l1_validator_tx_test.go} | 24 +- ...json => disable_l1_validator_tx_test.json} | 0 .../txs/executor/atomic_tx_executor.go | 10 +- .../txs/executor/create_chain_test.go | 4 +- .../txs/executor/proposal_tx_executor.go | 10 +- .../txs/executor/standard_tx_executor.go | 166 +++---- .../txs/executor/standard_tx_executor_test.go | 290 ++++++------ vms/platformvm/txs/executor/state_changes.go | 36 +- .../txs/executor/state_changes_test.go | 66 +-- .../txs/executor/subnet_tx_verification.go | 2 +- vms/platformvm/txs/executor/warp_verifier.go | 10 +- .../txs/executor/warp_verifier_test.go | 36 +- vms/platformvm/txs/fee/calculator_test.go | 30 +- vms/platformvm/txs/fee/complexity.go | 64 +-- vms/platformvm/txs/fee/complexity_test.go | 12 +- vms/platformvm/txs/fee/static_calculator.go | 10 +- ...go => increase_l1_validator_balance_tx.go} | 10 +- ... increase_l1_validator_balance_tx_test.go} | 24 +- ...ncrease_l1_validator_balance_tx_test.json} | 0 ...ator_tx.go => register_l1_validator_tx.go} | 12 +- ...st.go => register_l1_validator_tx_test.go} | 22 +- ...son => register_l1_validator_tx_test.json} | 0 ...ht_tx.go => set_l1_validator_weight_tx.go} | 12 +- ....go => set_l1_validator_weight_tx_test.go} | 22 +- ...n => set_l1_validator_weight_tx_test.json} | 0 vms/platformvm/txs/txstest/wallet.go | 4 +- vms/platformvm/txs/visitor.go | 10 +- vms/platformvm/warp/message/codec.go | 8 +- ...ration.go => l1_validator_registration.go} | 22 +- ...t.go => l1_validator_registration_test.go} | 6 +- ...dator_weight.go => l1_validator_weight.go} | 21 +- ...ht_test.go => l1_validator_weight_test.go} | 16 +- vms/platformvm/warp/message/payload_test.go | 24 +- ..._validator.go => register_l1_validator.go} | 24 +- ..._test.go => register_l1_validator_test.go} | 24 +- .../warp/message/subnet_conversion.go | 67 --- .../warp/message/subnet_to_l1_conversion.go | 68 +++ ...est.go => subnet_to_l1_conversion_test.go} | 20 +- wallet/chain/p/builder/builder.go | 79 ++-- wallet/chain/p/builder/with_options.go | 32 +- wallet/chain/p/builder_test.go | 26 +- wallet/chain/p/signer/visitor.go | 10 +- wallet/chain/p/wallet/backend_visitor.go | 18 +- wallet/chain/p/wallet/wallet.go | 57 +-- wallet/chain/p/wallet/with_options.go | 22 +- .../main.go | 14 +- .../main.go | 10 +- .../main.go | 8 +- .../main.go | 14 +- .../main.go | 10 +- .../main.go | 6 +- .../main.go | 12 +- .../main.go | 26 +- .../main.go | 14 +- .../main.go | 6 +- 98 files changed, 2869 insertions(+), 2871 deletions(-) create mode 100644 vms/platformvm/state/l1_validator.go create mode 100644 vms/platformvm/state/l1_validator_test.go delete mode 100644 vms/platformvm/state/subnet_only_validator.go delete mode 100644 vms/platformvm/state/subnet_only_validator_test.go rename vms/platformvm/txs/{convert_subnet_tx.go => convert_subnet_to_l1_tx.go} (85%) rename vms/platformvm/txs/{convert_subnet_tx_test.go => convert_subnet_to_l1_tx_test.go} (94%) rename vms/platformvm/txs/{convert_subnet_tx_test_complex.json => convert_subnet_to_l1_tx_test_complex.json} (100%) rename vms/platformvm/txs/{convert_subnet_tx_test_simple.json => convert_subnet_to_l1_tx_test_simple.json} (100%) rename vms/platformvm/txs/{disable_subnet_validator_tx.go => disable_l1_validator_tx.go} (75%) rename vms/platformvm/txs/{disable_subnet_validator_tx_test.go => disable_l1_validator_tx_test.go} (94%) rename vms/platformvm/txs/{disable_subnet_validator_tx_test.json => disable_l1_validator_tx_test.json} (100%) rename vms/platformvm/txs/{increase_balance_tx.go => increase_l1_validator_balance_tx.go} (74%) rename vms/platformvm/txs/{increase_balance_tx_test.go => increase_l1_validator_balance_tx_test.go} (94%) rename vms/platformvm/txs/{increase_balance_tx_test.json => increase_l1_validator_balance_tx_test.json} (100%) rename vms/platformvm/txs/{register_subnet_validator_tx.go => register_l1_validator_tx.go} (73%) rename vms/platformvm/txs/{register_subnet_validator_tx_test.go => register_l1_validator_tx_test.go} (95%) rename vms/platformvm/txs/{register_subnet_validator_tx_test.json => register_l1_validator_tx_test.json} (100%) rename vms/platformvm/txs/{set_subnet_validator_weight_tx.go => set_l1_validator_weight_tx.go} (65%) rename vms/platformvm/txs/{set_subnet_validator_weight_tx_test.go => set_l1_validator_weight_tx_test.go} (94%) rename vms/platformvm/txs/{set_subnet_validator_weight_tx_test.json => set_l1_validator_weight_tx_test.json} (100%) rename vms/platformvm/warp/message/{subnet_validator_registration.go => l1_validator_registration.go} (60%) rename vms/platformvm/warp/message/{subnet_validator_registration_test.go => l1_validator_registration_test.go} (76%) rename vms/platformvm/warp/message/{subnet_validator_weight.go => l1_validator_weight.go} (67%) rename vms/platformvm/warp/message/{subnet_validator_weight_test.go => l1_validator_weight_test.go} (69%) rename vms/platformvm/warp/message/{register_subnet_validator.go => register_l1_validator.go} (83%) rename vms/platformvm/warp/message/{register_subnet_validator_test.go => register_l1_validator_test.go} (86%) delete mode 100644 vms/platformvm/warp/message/subnet_conversion.go create mode 100644 vms/platformvm/warp/message/subnet_to_l1_conversion.go rename vms/platformvm/warp/message/{subnet_conversion_test.go => subnet_to_l1_conversion_test.go} (82%) rename wallet/subnet/primary/examples/{convert-subnet => convert-subnet-to-l1}/main.go (88%) rename wallet/subnet/primary/examples/{disable-subnet-validator => disable-l1-validator}/main.go (81%) rename wallet/subnet/primary/examples/{increase-balance => increase-l1-validator-balance}/main.go (85%) rename wallet/subnet/primary/examples/{register-subnet-validator => register-l1-validator}/main.go (85%) rename wallet/subnet/primary/examples/{set-subnet-validator-weight => set-l1-validator-weight}/main.go (89%) rename wallet/subnet/primary/examples/{sign-subnet-validator-registration => sign-l1-validator-registration}/main.go (93%) rename wallet/subnet/primary/examples/{sign-subnet-validator-removal-genesis => sign-l1-validator-removal-genesis}/main.go (89%) rename wallet/subnet/primary/examples/{sign-subnet-validator-removal-registration => sign-l1-validator-removal-registration}/main.go (83%) rename wallet/subnet/primary/examples/{sign-subnet-validator-weight => sign-l1-validator-weight}/main.go (87%) rename wallet/subnet/primary/examples/{sign-subnet-conversion => sign-subnet-to-l1-conversion}/main.go (94%) diff --git a/RELEASES.md b/RELEASES.md index 0e44c8de5a2c..4f64902a0026 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -4,7 +4,7 @@ ### APIs -- Added `platform.getSubnetOnlyValidator` +- Added `platform.getL1Validator` - Added `platform.getProposedHeight` ### Configs diff --git a/proto/pb/platformvm/platformvm.pb.go b/proto/pb/platformvm/platformvm.pb.go index 452e02d077d0..e5a0831959ae 100644 --- a/proto/pb/platformvm/platformvm.pb.go +++ b/proto/pb/platformvm/platformvm.pb.go @@ -20,20 +20,20 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type SubnetValidatorRegistrationJustification struct { +type L1ValidatorRegistrationJustification struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Types that are assignable to Preimage: // - // *SubnetValidatorRegistrationJustification_ConvertSubnetTxData - // *SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage - Preimage isSubnetValidatorRegistrationJustification_Preimage `protobuf_oneof:"preimage"` + // *L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData + // *L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage + Preimage isL1ValidatorRegistrationJustification_Preimage `protobuf_oneof:"preimage"` } -func (x *SubnetValidatorRegistrationJustification) Reset() { - *x = SubnetValidatorRegistrationJustification{} +func (x *L1ValidatorRegistrationJustification) Reset() { + *x = L1ValidatorRegistrationJustification{} if protoimpl.UnsafeEnabled { mi := &file_platformvm_platformvm_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -41,13 +41,13 @@ func (x *SubnetValidatorRegistrationJustification) Reset() { } } -func (x *SubnetValidatorRegistrationJustification) String() string { +func (x *L1ValidatorRegistrationJustification) String() string { return protoimpl.X.MessageStringOf(x) } -func (*SubnetValidatorRegistrationJustification) ProtoMessage() {} +func (*L1ValidatorRegistrationJustification) ProtoMessage() {} -func (x *SubnetValidatorRegistrationJustification) ProtoReflect() protoreflect.Message { +func (x *L1ValidatorRegistrationJustification) ProtoReflect() protoreflect.Message { mi := &file_platformvm_platformvm_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -59,55 +59,55 @@ func (x *SubnetValidatorRegistrationJustification) ProtoReflect() protoreflect.M return mi.MessageOf(x) } -// Deprecated: Use SubnetValidatorRegistrationJustification.ProtoReflect.Descriptor instead. -func (*SubnetValidatorRegistrationJustification) Descriptor() ([]byte, []int) { +// Deprecated: Use L1ValidatorRegistrationJustification.ProtoReflect.Descriptor instead. +func (*L1ValidatorRegistrationJustification) Descriptor() ([]byte, []int) { return file_platformvm_platformvm_proto_rawDescGZIP(), []int{0} } -func (m *SubnetValidatorRegistrationJustification) GetPreimage() isSubnetValidatorRegistrationJustification_Preimage { +func (m *L1ValidatorRegistrationJustification) GetPreimage() isL1ValidatorRegistrationJustification_Preimage { if m != nil { return m.Preimage } return nil } -func (x *SubnetValidatorRegistrationJustification) GetConvertSubnetTxData() *SubnetIDIndex { - if x, ok := x.GetPreimage().(*SubnetValidatorRegistrationJustification_ConvertSubnetTxData); ok { - return x.ConvertSubnetTxData +func (x *L1ValidatorRegistrationJustification) GetConvertSubnetToL1TxData() *SubnetIDIndex { + if x, ok := x.GetPreimage().(*L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData); ok { + return x.ConvertSubnetToL1TxData } return nil } -func (x *SubnetValidatorRegistrationJustification) GetRegisterSubnetValidatorMessage() []byte { - if x, ok := x.GetPreimage().(*SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage); ok { - return x.RegisterSubnetValidatorMessage +func (x *L1ValidatorRegistrationJustification) GetRegisterL1ValidatorMessage() []byte { + if x, ok := x.GetPreimage().(*L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage); ok { + return x.RegisterL1ValidatorMessage } return nil } -type isSubnetValidatorRegistrationJustification_Preimage interface { - isSubnetValidatorRegistrationJustification_Preimage() +type isL1ValidatorRegistrationJustification_Preimage interface { + isL1ValidatorRegistrationJustification_Preimage() } -type SubnetValidatorRegistrationJustification_ConvertSubnetTxData struct { +type L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData struct { // This should be set to obtain an attestation that a validator specified in - // a ConvertSubnetTx has been removed from the validator set. - ConvertSubnetTxData *SubnetIDIndex `protobuf:"bytes,1,opt,name=convert_subnet_tx_data,json=convertSubnetTxData,proto3,oneof"` + // a ConvertSubnetToL1Tx has been removed from the validator set. + ConvertSubnetToL1TxData *SubnetIDIndex `protobuf:"bytes,1,opt,name=convert_subnet_to_l1_tx_data,json=convertSubnetToL1TxData,proto3,oneof"` } -type SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage struct { - // This should be set to a RegisterSubnetValidatorMessage to obtain an +type L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage struct { + // This should be set to a RegisterL1ValidatorMessage to obtain an // attestation that a validator is not currently registered and can never be // registered. This can be because the validator was successfully added and // then later removed, or because the validator was never added and the // registration expired. - RegisterSubnetValidatorMessage []byte `protobuf:"bytes,2,opt,name=register_subnet_validator_message,json=registerSubnetValidatorMessage,proto3,oneof"` + RegisterL1ValidatorMessage []byte `protobuf:"bytes,2,opt,name=register_l1_validator_message,json=registerL1ValidatorMessage,proto3,oneof"` } -func (*SubnetValidatorRegistrationJustification_ConvertSubnetTxData) isSubnetValidatorRegistrationJustification_Preimage() { +func (*L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData) isL1ValidatorRegistrationJustification_Preimage() { } -func (*SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage) isSubnetValidatorRegistrationJustification_Preimage() { +func (*L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage) isL1ValidatorRegistrationJustification_Preimage() { } type SubnetIDIndex struct { @@ -170,29 +170,29 @@ var File_platformvm_platformvm_proto protoreflect.FileDescriptor var file_platformvm_platformvm_proto_rawDesc = []byte{ 0x0a, 0x1b, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x2f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x70, - 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x22, 0xd5, 0x01, 0x0a, 0x28, 0x53, 0x75, - 0x62, 0x6e, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x67, - 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4a, 0x75, 0x73, 0x74, 0x69, 0x66, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x50, 0x0a, 0x16, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, - 0x74, 0x5f, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x74, 0x78, 0x5f, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, - 0x6d, 0x76, 0x6d, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x49, 0x6e, 0x64, 0x65, - 0x78, 0x48, 0x00, 0x52, 0x13, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x53, 0x75, 0x62, 0x6e, - 0x65, 0x74, 0x54, 0x78, 0x44, 0x61, 0x74, 0x61, 0x12, 0x4b, 0x0a, 0x21, 0x72, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x65, 0x72, 0x5f, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x1e, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, - 0x75, 0x62, 0x6e, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x4d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x70, 0x72, 0x65, 0x69, 0x6d, 0x61, 0x67, - 0x65, 0x22, 0x42, 0x0a, 0x0d, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x49, 0x6e, 0x64, - 0x65, 0x78, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x64, 0x12, - 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, - 0x69, 0x6e, 0x64, 0x65, 0x78, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, - 0x62, 0x2f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x22, 0xd3, 0x01, 0x0a, 0x24, 0x4c, 0x31, + 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4a, 0x75, 0x73, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x5a, 0x0a, 0x1c, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f, 0x73, 0x75, + 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x6c, 0x31, 0x5f, 0x74, 0x78, 0x5f, 0x64, 0x61, + 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x6c, 0x61, 0x74, 0x66, + 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x49, 0x6e, + 0x64, 0x65, 0x78, 0x48, 0x00, 0x52, 0x17, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x53, 0x75, + 0x62, 0x6e, 0x65, 0x74, 0x54, 0x6f, 0x4c, 0x31, 0x54, 0x78, 0x44, 0x61, 0x74, 0x61, 0x12, 0x43, + 0x0a, 0x1d, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x5f, 0x6c, 0x31, 0x5f, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x1a, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, + 0x72, 0x4c, 0x31, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x70, 0x72, 0x65, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x22, + 0x42, 0x0a, 0x0d, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x49, 0x6e, 0x64, 0x65, 0x78, + 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, + 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, + 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x76, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -209,11 +209,11 @@ func file_platformvm_platformvm_proto_rawDescGZIP() []byte { var file_platformvm_platformvm_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_platformvm_platformvm_proto_goTypes = []interface{}{ - (*SubnetValidatorRegistrationJustification)(nil), // 0: platformvm.SubnetValidatorRegistrationJustification - (*SubnetIDIndex)(nil), // 1: platformvm.SubnetIDIndex + (*L1ValidatorRegistrationJustification)(nil), // 0: platformvm.L1ValidatorRegistrationJustification + (*SubnetIDIndex)(nil), // 1: platformvm.SubnetIDIndex } var file_platformvm_platformvm_proto_depIdxs = []int32{ - 1, // 0: platformvm.SubnetValidatorRegistrationJustification.convert_subnet_tx_data:type_name -> platformvm.SubnetIDIndex + 1, // 0: platformvm.L1ValidatorRegistrationJustification.convert_subnet_to_l1_tx_data:type_name -> platformvm.SubnetIDIndex 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -228,7 +228,7 @@ func file_platformvm_platformvm_proto_init() { } if !protoimpl.UnsafeEnabled { file_platformvm_platformvm_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SubnetValidatorRegistrationJustification); i { + switch v := v.(*L1ValidatorRegistrationJustification); i { case 0: return &v.state case 1: @@ -253,8 +253,8 @@ func file_platformvm_platformvm_proto_init() { } } file_platformvm_platformvm_proto_msgTypes[0].OneofWrappers = []interface{}{ - (*SubnetValidatorRegistrationJustification_ConvertSubnetTxData)(nil), - (*SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage)(nil), + (*L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData)(nil), + (*L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage)(nil), } type x struct{} out := protoimpl.TypeBuilder{ diff --git a/proto/pb/validatorstate/validator_state.pb.go b/proto/pb/validatorstate/validator_state.pb.go index 055ed82b715b..723dc39e91ea 100644 --- a/proto/pb/validatorstate/validator_state.pb.go +++ b/proto/pb/validatorstate/validator_state.pb.go @@ -316,14 +316,14 @@ type Validator struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NodeId []byte `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` - Weight uint64 `protobuf:"varint,2,opt,name=weight,proto3" json:"weight,omitempty"` - PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` // Uncompressed public key, can be empty - StartTime uint64 `protobuf:"varint,4,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` // can be empty - MinNonce uint64 `protobuf:"varint,5,opt,name=min_nonce,json=minNonce,proto3" json:"min_nonce,omitempty"` // can be empty - IsActive bool `protobuf:"varint,6,opt,name=is_active,json=isActive,proto3" json:"is_active,omitempty"` // can be empty - ValidationId []byte `protobuf:"bytes,7,opt,name=validation_id,json=validationId,proto3" json:"validation_id,omitempty"` // can be empty - IsSov bool `protobuf:"varint,8,opt,name=is_sov,json=isSov,proto3" json:"is_sov,omitempty"` // can be empty + NodeId []byte `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` + Weight uint64 `protobuf:"varint,2,opt,name=weight,proto3" json:"weight,omitempty"` + PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` // Uncompressed public key, can be empty + StartTime uint64 `protobuf:"varint,4,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` // can be empty + MinNonce uint64 `protobuf:"varint,5,opt,name=min_nonce,json=minNonce,proto3" json:"min_nonce,omitempty"` // can be empty + IsActive bool `protobuf:"varint,6,opt,name=is_active,json=isActive,proto3" json:"is_active,omitempty"` // can be empty + ValidationId []byte `protobuf:"bytes,7,opt,name=validation_id,json=validationId,proto3" json:"validation_id,omitempty"` // can be empty + IsL1Validator bool `protobuf:"varint,8,opt,name=is_l1_validator,json=isL1Validator,proto3" json:"is_l1_validator,omitempty"` // can be empty } func (x *Validator) Reset() { @@ -407,9 +407,9 @@ func (x *Validator) GetValidationId() []byte { return nil } -func (x *Validator) GetIsSov() bool { +func (x *Validator) GetIsL1Validator() bool { if x != nil { - return x.IsSov + return x.IsL1Validator } return false } @@ -545,7 +545,7 @@ var file_validatorstate_validator_state_proto_rawDesc = []byte{ 0x3c, 0x0a, 0x1d, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x64, 0x22, 0xf0, 0x01, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x64, 0x22, 0x81, 0x02, 0x0a, 0x09, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, @@ -559,58 +559,59 @@ var file_validatorstate_validator_state_proto_rawDesc = []byte{ 0x74, 0x69, 0x76, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x69, 0x73, 0x5f, - 0x73, 0x6f, 0x76, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x69, 0x73, 0x53, 0x6f, 0x76, - 0x22, 0x54, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, - 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x76, - 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x19, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, - 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x22, 0x82, 0x01, 0x0a, 0x1e, 0x47, 0x65, 0x74, 0x43, 0x75, + 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x0f, 0x69, 0x73, 0x5f, + 0x6c, 0x31, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x4c, 0x31, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, + 0x72, 0x22, 0x54, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, + 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x0a, + 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x0a, 0x76, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x22, 0x82, 0x01, 0x0a, 0x1e, 0x47, 0x65, 0x74, 0x43, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, + 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, + 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, + 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x63, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x32, 0xf1, 0x03, 0x0a, + 0x0e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, + 0x54, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x6e, 0x69, 0x6d, 0x75, 0x6d, 0x48, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x28, 0x2e, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, + 0x4d, 0x69, 0x6e, 0x69, 0x6d, 0x75, 0x6d, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x1a, 0x28, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0b, 0x47, + 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x12, 0x22, 0x2e, 0x76, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, + 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, + 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, + 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, + 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x12, 0x26, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, + 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, + 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x77, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x56, - 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x6f, 0x72, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, - 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x63, 0x75, - 0x72, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x32, 0xf1, 0x03, 0x0a, 0x0e, - 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x54, - 0x0a, 0x10, 0x47, 0x65, 0x74, 0x4d, 0x69, 0x6e, 0x69, 0x6d, 0x75, 0x6d, 0x48, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x28, 0x2e, 0x76, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x4d, - 0x69, 0x6e, 0x69, 0x6d, 0x75, 0x6d, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, - 0x6e, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x1a, 0x28, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, - 0x65, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x48, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, 0x0a, 0x0b, 0x47, 0x65, - 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x12, 0x22, 0x2e, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, - 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, - 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, - 0x65, 0x74, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x6f, 0x72, 0x53, 0x65, 0x74, 0x12, 0x26, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, - 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, - 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, - 0x65, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x77, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, - 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, - 0x12, 0x2d, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, + 0x74, 0x12, 0x2d, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2e, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x2e, 0x2e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, - 0x2e, 0x47, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, - 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, - 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x64, 0x61, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, + 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, + 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x76, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/proto/platformvm/platformvm.proto b/proto/platformvm/platformvm.proto index f1688d16592c..123621bc16c5 100644 --- a/proto/platformvm/platformvm.proto +++ b/proto/platformvm/platformvm.proto @@ -4,17 +4,17 @@ package platformvm; option go_package = "github.com/ava-labs/avalanchego/proto/pb/platformvm"; -message SubnetValidatorRegistrationJustification { +message L1ValidatorRegistrationJustification { oneof preimage { // This should be set to obtain an attestation that a validator specified in - // a ConvertSubnetTx has been removed from the validator set. - SubnetIDIndex convert_subnet_tx_data = 1; - // This should be set to a RegisterSubnetValidatorMessage to obtain an + // a ConvertSubnetToL1Tx has been removed from the validator set. + SubnetIDIndex convert_subnet_to_l1_tx_data = 1; + // This should be set to a RegisterL1ValidatorMessage to obtain an // attestation that a validator is not currently registered and can never be // registered. This can be because the validator was successfully added and // then later removed, or because the validator was never added and the // registration expired. - bytes register_subnet_validator_message = 2; + bytes register_l1_validator_message = 2; } } diff --git a/proto/validatorstate/validator_state.proto b/proto/validatorstate/validator_state.proto index 10170f2e5870..917ce10b214e 100644 --- a/proto/validatorstate/validator_state.proto +++ b/proto/validatorstate/validator_state.proto @@ -55,7 +55,7 @@ message Validator { uint64 min_nonce = 5; // can be empty bool is_active = 6; // can be empty bytes validation_id = 7; // can be empty - bool is_sov = 8; // can be empty + bool is_l1_validator = 8; // can be empty } message GetValidatorSetResponse { diff --git a/snow/networking/router/chain_router.go b/snow/networking/router/chain_router.go index 16cac1df54d3..3893d2aeeb94 100644 --- a/snow/networking/router/chain_router.go +++ b/snow/networking/router/chain_router.go @@ -464,7 +464,7 @@ func (cr *ChainRouter) Connected(nodeID ids.NodeID, nodeVersion *version.Applica msg := message.InternalConnected(nodeID, nodeVersion) // TODO: fire up an event when validator state changes i.e when they leave - // set, disconnect. we cannot put a subnet-only validator check here since + // set, disconnect. we cannot put an L1 validator check here since // Disconnected would not be handled properly. // // When sybil protection is disabled, we only want this clause to happen @@ -509,7 +509,7 @@ func (cr *ChainRouter) Disconnected(nodeID ids.NodeID) { msg := message.InternalDisconnected(nodeID) // TODO: fire up an event when validator state changes i.e when they leave - // set, disconnect. we cannot put a subnet-only validator check here since + // set, disconnect. we cannot put an L1 validator check here since // if a validator connects then it leaves validator-set, it would not be // disconnected properly. for _, chain := range cr.chainHandlers { diff --git a/snow/validators/gvalidators/validator_state_client.go b/snow/validators/gvalidators/validator_state_client.go index 0fb10fad4d3a..be1b91c44d0b 100644 --- a/snow/validators/gvalidators/validator_state_client.go +++ b/snow/validators/gvalidators/validator_state_client.go @@ -130,14 +130,14 @@ func (c *Client) GetCurrentValidatorSet( } vdrs[validationID] = &validators.GetCurrentValidatorOutput{ - ValidationID: validationID, - NodeID: nodeID, - PublicKey: publicKey, - Weight: validator.Weight, - StartTime: validator.StartTime, - MinNonce: validator.MinNonce, - IsActive: validator.IsActive, - IsSoV: validator.IsSov, + ValidationID: validationID, + NodeID: nodeID, + PublicKey: publicKey, + Weight: validator.Weight, + StartTime: validator.StartTime, + MinNonce: validator.MinNonce, + IsActive: validator.IsActive, + IsL1Validator: validator.IsL1Validator, } } return vdrs, resp.GetCurrentHeight(), nil diff --git a/snow/validators/gvalidators/validator_state_server.go b/snow/validators/gvalidators/validator_state_server.go index d58c61099319..668bf967df63 100644 --- a/snow/validators/gvalidators/validator_state_server.go +++ b/snow/validators/gvalidators/validator_state_server.go @@ -100,13 +100,13 @@ func (s *Server) GetCurrentValidatorSet(ctx context.Context, req *pb.GetCurrentV i := 0 for _, vdr := range vdrs { vdrPB := &pb.Validator{ - NodeId: vdr.NodeID.Bytes(), - StartTime: vdr.StartTime, - IsActive: vdr.IsActive, - ValidationId: vdr.ValidationID[:], - Weight: vdr.Weight, - MinNonce: vdr.MinNonce, - IsSov: vdr.IsSoV, + NodeId: vdr.NodeID.Bytes(), + StartTime: vdr.StartTime, + IsActive: vdr.IsActive, + ValidationId: vdr.ValidationID[:], + Weight: vdr.Weight, + MinNonce: vdr.MinNonce, + IsL1Validator: vdr.IsL1Validator, } if vdr.PublicKey != nil { // Passing in the uncompressed bytes is a performance optimization diff --git a/snow/validators/validator.go b/snow/validators/validator.go index 4e11c0cc0085..837e955f41e7 100644 --- a/snow/validators/validator.go +++ b/snow/validators/validator.go @@ -31,12 +31,12 @@ type GetValidatorOutput struct { } type GetCurrentValidatorOutput struct { - ValidationID ids.ID - NodeID ids.NodeID - PublicKey *bls.PublicKey - Weight uint64 - StartTime uint64 - MinNonce uint64 - IsActive bool - IsSoV bool + ValidationID ids.ID + NodeID ids.NodeID + PublicKey *bls.PublicKey + Weight uint64 + StartTime uint64 + MinNonce uint64 + IsActive bool + IsL1Validator bool } diff --git a/tests/e2e/p/l1.go b/tests/e2e/p/l1.go index d3bcb63e168d..c5e62d75ac55 100644 --- a/tests/e2e/p/l1.go +++ b/tests/e2e/p/l1.go @@ -209,12 +209,12 @@ var _ = e2e.DescribePChain("[L1]", func() { require.NoError(err) address := []byte{} - tc.By("issuing a ConvertSubnetTx", func() { - tx, err := pWallet.IssueConvertSubnetTx( + tc.By("issuing a ConvertSubnetToL1Tx", func() { + tx, err := pWallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ { NodeID: subnetGenesisNode.NodeID.Bytes(), Weight: genesisWeight, @@ -245,11 +245,11 @@ var _ = e2e.DescribePChain("[L1]", func() { genesisValidationID := subnetID.Append(0) tc.By("verifying the Permissioned Subnet was converted to an L1", func() { - expectedConversionID, err := warpmessage.SubnetConversionID(warpmessage.SubnetConversionData{ + expectedConversionID, err := warpmessage.SubnetToL1ConversionID(warpmessage.SubnetToL1ConversionData{ SubnetID: subnetID, ManagerChainID: chainID, ManagerAddress: address, - Validators: []warpmessage.SubnetConversionValidatorData{ + Validators: []warpmessage.SubnetToL1ConverstionValidatorData{ { NodeID: subnetGenesisNode.NodeID.Bytes(), BLSPublicKey: genesisNodePoP.PublicKey, @@ -287,15 +287,15 @@ var _ = e2e.DescribePChain("[L1]", func() { }) }) - tc.By("verifying the SoV can be fetched", func() { - sov, _, err := pClient.GetSubnetOnlyValidator(tc.DefaultContext(), genesisValidationID) + tc.By("verifying the L1 validator can be fetched", func() { + l1Validator, _, err := pClient.GetL1Validator(tc.DefaultContext(), genesisValidationID) require.NoError(err) - require.LessOrEqual(sov.Balance, genesisBalance) + require.LessOrEqual(l1Validator.Balance, genesisBalance) - sov.StartTime = 0 - sov.Balance = 0 + l1Validator.StartTime = 0 + l1Validator.Balance = 0 require.Equal( - platformvm.SubnetOnlyValidator{ + platformvm.L1Validator{ SubnetID: subnetID, NodeID: subnetGenesisNode.NodeID, PublicKey: genesisNodePK, @@ -308,37 +308,37 @@ var _ = e2e.DescribePChain("[L1]", func() { Weight: genesisWeight, MinNonce: 0, }, - sov, + l1Validator, ) }) tc.By("fetching the subnet conversion attestation", func() { - unsignedSubnetConversion := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + unsignedSubnetToL1Conversion := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, constants.PlatformChainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( nil, - must[*warpmessage.SubnetConversion](tc)(warpmessage.NewSubnetConversion( + must[*warpmessage.SubnetToL1Conversion](tc)(warpmessage.NewSubnetToL1Conversion( expectedConversionID, )).Bytes(), )).Bytes(), )) tc.By("sending the request to sign the warp message", func() { - registerSubnetValidatorRequest, err := wrapWarpSignatureRequest( - unsignedSubnetConversion, + registerL1ValidatorRequest, err := wrapWarpSignatureRequest( + unsignedSubnetToL1Conversion, subnetID[:], ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), registerSubnetValidatorRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), registerL1ValidatorRequest)) }) tc.By("getting the signature response", func() { signature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) - require.True(bls.Verify(genesisNodePK, signature, unsignedSubnetConversion.Bytes())) + require.True(bls.Verify(genesisNodePK, signature, unsignedSubnetToL1Conversion.Bytes())) }) }) }) @@ -366,9 +366,9 @@ var _ = e2e.DescribePChain("[L1]", func() { e2e.WaitForHealthy(tc, subnetRegisterNode) }) - tc.By("creating the RegisterSubnetValidatorMessage") + tc.By("creating the RegisterL1ValidatorMessage") expiry := uint64(time.Now().Add(expiryDelay).Unix()) // This message will expire in 5 minutes - registerSubnetValidatorMessage, err := warpmessage.NewRegisterSubnetValidator( + registerL1ValidatorMessage, err := warpmessage.NewRegisterL1Validator( subnetID, subnetRegisterNode.NodeID, registerNodePoP.PublicKey, @@ -378,51 +378,51 @@ var _ = e2e.DescribePChain("[L1]", func() { registerWeight, ) require.NoError(err) - registerValidationID := registerSubnetValidatorMessage.ValidationID() + registerValidationID := registerL1ValidatorMessage.ValidationID() tc.By("registering the validator", func() { tc.By("creating the unsigned warp message") - unsignedRegisterSubnetValidator := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + unsignedRegisterL1Validator := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, chainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( address, - registerSubnetValidatorMessage.Bytes(), + registerL1ValidatorMessage.Bytes(), )).Bytes(), )) tc.By("sending the request to sign the warp message", func() { - registerSubnetValidatorRequest, err := wrapWarpSignatureRequest( - unsignedRegisterSubnetValidator, + registerL1ValidatorRequest, err := wrapWarpSignatureRequest( + unsignedRegisterL1Validator, nil, ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), registerSubnetValidatorRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), registerL1ValidatorRequest)) }) tc.By("getting the signature response") - registerSubnetValidatorSignature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) + registerL1ValidatorSignature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) tc.By("creating the signed warp message to register the validator") - registerSubnetValidator, err := warp.NewMessage( - unsignedRegisterSubnetValidator, + registerL1Validator, err := warp.NewMessage( + unsignedRegisterL1Validator, &warp.BitSetSignature{ Signers: set.NewBits(0).Bytes(), // [signers] has weight from the genesis peer Signature: ([bls.SignatureLen]byte)( - bls.SignatureToBytes(registerSubnetValidatorSignature), + bls.SignatureToBytes(registerL1ValidatorSignature), ), }, ) require.NoError(err) - tc.By("issuing a RegisterSubnetValidatorTx", func() { - tx, err := pWallet.IssueRegisterSubnetValidatorTx( + tc.By("issuing a RegisterL1ValidatorTx", func() { + tx, err := pWallet.IssueRegisterL1ValidatorTx( registerBalance, registerNodePoP.ProofOfPossession, - registerSubnetValidator.Bytes(), + registerL1Validator.Bytes(), ) require.NoError(err) @@ -459,13 +459,13 @@ var _ = e2e.DescribePChain("[L1]", func() { }) }) - tc.By("verifying the SoV can be fetched", func() { - sov, _, err := pClient.GetSubnetOnlyValidator(tc.DefaultContext(), registerValidationID) + tc.By("verifying the L1 validator can be fetched", func() { + l1Validator, _, err := pClient.GetL1Validator(tc.DefaultContext(), registerValidationID) require.NoError(err) - sov.StartTime = 0 + l1Validator.StartTime = 0 require.Equal( - platformvm.SubnetOnlyValidator{ + platformvm.L1Validator{ SubnetID: subnetID, NodeID: subnetRegisterNode.NodeID, PublicKey: registerNodePK, @@ -479,17 +479,17 @@ var _ = e2e.DescribePChain("[L1]", func() { MinNonce: 0, Balance: 0, }, - sov, + l1Validator, ) }) tc.By("fetching the validator registration attestation", func() { - unsignedSubnetValidatorRegistration := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + unsignedL1ValidatorRegistration := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, constants.PlatformChainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( nil, - must[*warpmessage.SubnetValidatorRegistration](tc)(warpmessage.NewSubnetValidatorRegistration( + must[*warpmessage.L1ValidatorRegistration](tc)(warpmessage.NewL1ValidatorRegistration( registerValidationID, true, // registered )).Bytes(), @@ -497,33 +497,33 @@ var _ = e2e.DescribePChain("[L1]", func() { )) tc.By("sending the request to sign the warp message", func() { - subnetValidatorRegistrationRequest, err := wrapWarpSignatureRequest( - unsignedSubnetValidatorRegistration, + l1ValidatorRegistrationRequest, err := wrapWarpSignatureRequest( + unsignedL1ValidatorRegistration, nil, ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), subnetValidatorRegistrationRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), l1ValidatorRegistrationRequest)) }) tc.By("getting the signature response", func() { signature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) - require.True(bls.Verify(genesisNodePK, signature, unsignedSubnetValidatorRegistration.Bytes())) + require.True(bls.Verify(genesisNodePK, signature, unsignedL1ValidatorRegistration.Bytes())) }) }) }) var nextNonce uint64 setWeight := func(validationID ids.ID, weight uint64) { - tc.By("creating the unsigned SubnetValidatorWeightMessage") - unsignedSubnetValidatorWeight := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + tc.By("creating the unsigned L1ValidatorWeightMessage") + unsignedL1ValidatorWeight := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, chainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( address, - must[*warpmessage.SubnetValidatorWeight](tc)(warpmessage.NewSubnetValidatorWeight( + must[*warpmessage.L1ValidatorWeight](tc)(warpmessage.NewL1ValidatorWeight( validationID, nextNonce, weight, @@ -532,35 +532,35 @@ var _ = e2e.DescribePChain("[L1]", func() { )) tc.By("sending the request to sign the warp message", func() { - setSubnetValidatorWeightRequest, err := wrapWarpSignatureRequest( - unsignedSubnetValidatorWeight, + setL1ValidatorWeightRequest, err := wrapWarpSignatureRequest( + unsignedL1ValidatorWeight, nil, ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), setSubnetValidatorWeightRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), setL1ValidatorWeightRequest)) }) tc.By("getting the signature response") - setSubnetValidatorWeightSignature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) + setL1ValidatorWeightSignature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) tc.By("creating the signed warp message to increase the weight of the validator") - setSubnetValidatorWeight, err := warp.NewMessage( - unsignedSubnetValidatorWeight, + setL1ValidatorWeight, err := warp.NewMessage( + unsignedL1ValidatorWeight, &warp.BitSetSignature{ Signers: set.NewBits(0).Bytes(), // [signers] has weight from the genesis validator Signature: ([bls.SignatureLen]byte)( - bls.SignatureToBytes(setSubnetValidatorWeightSignature), + bls.SignatureToBytes(setL1ValidatorWeightSignature), ), }, ) require.NoError(err) - tc.By("issuing a SetSubnetValidatorWeightTx", func() { - tx, err := pWallet.IssueSetSubnetValidatorWeightTx( - setSubnetValidatorWeight.Bytes(), + tc.By("issuing a SetL1ValidatorWeightTx", func() { + tx, err := pWallet.IssueSetL1ValidatorWeightTx( + setL1ValidatorWeight.Bytes(), ) require.NoError(err) @@ -603,13 +603,13 @@ var _ = e2e.DescribePChain("[L1]", func() { }) }) - tc.By("verifying the SoV can be fetched", func() { - sov, _, err := pClient.GetSubnetOnlyValidator(tc.DefaultContext(), registerValidationID) + tc.By("verifying the L1 validator can be fetched", func() { + l1Validator, _, err := pClient.GetL1Validator(tc.DefaultContext(), registerValidationID) require.NoError(err) - sov.StartTime = 0 + l1Validator.StartTime = 0 require.Equal( - platformvm.SubnetOnlyValidator{ + platformvm.L1Validator{ SubnetID: subnetID, NodeID: subnetRegisterNode.NodeID, PublicKey: registerNodePK, @@ -623,17 +623,17 @@ var _ = e2e.DescribePChain("[L1]", func() { MinNonce: nextNonce, Balance: 0, }, - sov, + l1Validator, ) }) tc.By("fetching the validator weight change attestation", func() { - unsignedSubnetValidatorWeight := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + unsignedL1ValidatorWeight := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, constants.PlatformChainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( nil, - must[*warpmessage.SubnetValidatorWeight](tc)(warpmessage.NewSubnetValidatorWeight( + must[*warpmessage.L1ValidatorWeight](tc)(warpmessage.NewL1ValidatorWeight( registerValidationID, nextNonce-1, // Use the prior nonce updatedWeight, @@ -642,26 +642,26 @@ var _ = e2e.DescribePChain("[L1]", func() { )) tc.By("sending the request to sign the warp message", func() { - subnetValidatorRegistrationRequest, err := wrapWarpSignatureRequest( - unsignedSubnetValidatorWeight, + l1ValidatorRegistrationRequest, err := wrapWarpSignatureRequest( + unsignedL1ValidatorWeight, nil, ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), subnetValidatorRegistrationRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), l1ValidatorRegistrationRequest)) }) tc.By("getting the signature response", func() { signature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) - require.True(bls.Verify(genesisNodePK, signature, unsignedSubnetValidatorWeight.Bytes())) + require.True(bls.Verify(genesisNodePK, signature, unsignedL1ValidatorWeight.Bytes())) }) }) }) - tc.By("issuing an IncreaseBalanceTx", func() { - _, err := pWallet.IssueIncreaseBalanceTx( + tc.By("issuing an IncreaseL1ValidatorBalanceTx", func() { + _, err := pWallet.IssueIncreaseL1ValidatorBalanceTx( registerValidationID, units.Avax, ) @@ -683,8 +683,8 @@ var _ = e2e.DescribePChain("[L1]", func() { }) }) - tc.By("issuing an DisableSubnetValidatorTx", func() { - _, err := pWallet.IssueDisableSubnetValidatorTx( + tc.By("issuing a DisableL1ValidatorTx", func() { + _, err := pWallet.IssueDisableL1ValidatorTx( registerValidationID, ) require.NoError(err) @@ -722,41 +722,41 @@ var _ = e2e.DescribePChain("[L1]", func() { }) tc.By("fetching the validator removal attestation", func() { - unsignedSubnetValidatorRegistration := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( + unsignedL1ValidatorRegistration := must[*warp.UnsignedMessage](tc)(warp.NewUnsignedMessage( networkID, constants.PlatformChainID, must[*payload.AddressedCall](tc)(payload.NewAddressedCall( nil, - must[*warpmessage.SubnetValidatorRegistration](tc)(warpmessage.NewSubnetValidatorRegistration( + must[*warpmessage.L1ValidatorRegistration](tc)(warpmessage.NewL1ValidatorRegistration( registerValidationID, false, // removed )).Bytes(), )).Bytes(), )) - justification := platformvmpb.SubnetValidatorRegistrationJustification{ - Preimage: &platformvmpb.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorMessage.Bytes(), + justification := platformvmpb.L1ValidatorRegistrationJustification{ + Preimage: &platformvmpb.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorMessage.Bytes(), }, } justificationBytes, err := proto.Marshal(&justification) require.NoError(err) tc.By("sending the request to sign the warp message", func() { - subnetValidatorRegistrationRequest, err := wrapWarpSignatureRequest( - unsignedSubnetValidatorRegistration, + l1ValidatorRegistrationRequest, err := wrapWarpSignatureRequest( + unsignedL1ValidatorRegistration, justificationBytes, ) require.NoError(err) - require.True(genesisPeer.Send(tc.DefaultContext(), subnetValidatorRegistrationRequest)) + require.True(genesisPeer.Send(tc.DefaultContext(), l1ValidatorRegistrationRequest)) }) tc.By("getting the signature response", func() { signature, ok, err := findMessage(genesisPeerMessages, unwrapWarpSignature) require.NoError(err) require.True(ok) - require.True(bls.Verify(genesisNodePK, signature, unsignedSubnetValidatorRegistration.Bytes())) + require.True(bls.Verify(genesisNodePK, signature, unsignedL1ValidatorRegistration.Bytes())) }) }) }) diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 28735e4ea187..c47b4e6f8e40 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -91,9 +91,9 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) { // setup state to validate proposal block transaction onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes() onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes() - onParentAccept.EXPECT().GetSoVExcess().Return(gas.Gas(0)).AnyTimes() + onParentAccept.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).AnyTimes() onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes() - onParentAccept.EXPECT().NumActiveSubnetOnlyValidators().Return(0).AnyTimes() + onParentAccept.EXPECT().NumActiveL1Validators().Return(0).AnyTimes() onParentAccept.EXPECT().GetCurrentStakerIterator().Return( iterator.FromSlice(&state.Staker{ @@ -164,9 +164,9 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { onParentAccept := state.NewMockDiff(ctrl) onParentAccept.EXPECT().GetTimestamp().Return(parentTime).AnyTimes() onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes() - onParentAccept.EXPECT().GetSoVExcess().Return(gas.Gas(0)).AnyTimes() + onParentAccept.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).AnyTimes() onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes() - onParentAccept.EXPECT().NumActiveSubnetOnlyValidators().Return(0).AnyTimes() + onParentAccept.EXPECT().NumActiveL1Validators().Return(0).AnyTimes() onParentAccept.EXPECT().GetCurrentSupply(constants.PrimaryNetworkID).Return(uint64(1000), nil).AnyTimes() env.blkManager.(*manager).blkIDToState[parentID] = &blockState{ @@ -219,7 +219,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { ), nil }).AnyTimes() onParentAccept.EXPECT().GetPendingStakerIterator().Return(iterator.Empty[*state.Staker]{}, nil).AnyTimes() - onParentAccept.EXPECT().GetActiveSubnetOnlyValidatorsIterator().Return(iterator.Empty[state.SubnetOnlyValidator]{}, nil).AnyTimes() + onParentAccept.EXPECT().GetActiveL1ValidatorsIterator().Return(iterator.Empty[state.L1Validator]{}, nil).AnyTimes() onParentAccept.EXPECT().GetExpiryIterator().Return(iterator.Empty[state.ExpiryEntry]{}, nil).AnyTimes() onParentAccept.EXPECT().GetDelegateeReward(constants.PrimaryNetworkID, unsignedNextStakerTx.NodeID()).Return(uint64(0), nil).AnyTimes() diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 055e6c0e813a..f29d03516cd9 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -59,10 +59,10 @@ func TestApricotStandardBlockTimeVerification(t *testing.T) { chainTime := env.clk.Time().Truncate(time.Second) onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes() onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes() - onParentAccept.EXPECT().GetSoVExcess().Return(gas.Gas(0)).AnyTimes() + onParentAccept.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).AnyTimes() onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes() - onParentAccept.EXPECT().NumActiveSubnetOnlyValidators().Return(0).AnyTimes() - onParentAccept.EXPECT().GetActiveSubnetOnlyValidatorsIterator().Return(&iterator.Empty[state.SubnetOnlyValidator]{}, nil).AnyTimes() + onParentAccept.EXPECT().NumActiveL1Validators().Return(0).AnyTimes() + onParentAccept.EXPECT().GetActiveL1ValidatorsIterator().Return(&iterator.Empty[state.L1Validator]{}, nil).AnyTimes() // wrong height apricotChildBlk, err := block.NewApricotStandardBlock( @@ -131,14 +131,14 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) { }).AnyTimes() onParentAccept.EXPECT().GetPendingStakerIterator().Return(iterator.Empty[*state.Staker]{}, nil).AnyTimes() - onParentAccept.EXPECT().GetActiveSubnetOnlyValidatorsIterator().Return(iterator.Empty[state.SubnetOnlyValidator]{}, nil).AnyTimes() + onParentAccept.EXPECT().GetActiveL1ValidatorsIterator().Return(iterator.Empty[state.L1Validator]{}, nil).AnyTimes() onParentAccept.EXPECT().GetExpiryIterator().Return(iterator.Empty[state.ExpiryEntry]{}, nil).AnyTimes() onParentAccept.EXPECT().GetTimestamp().Return(chainTime).AnyTimes() onParentAccept.EXPECT().GetFeeState().Return(gas.State{}).AnyTimes() - onParentAccept.EXPECT().GetSoVExcess().Return(gas.Gas(0)).AnyTimes() + onParentAccept.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).AnyTimes() onParentAccept.EXPECT().GetAccruedFees().Return(uint64(0)).AnyTimes() - onParentAccept.EXPECT().NumActiveSubnetOnlyValidators().Return(0).AnyTimes() + onParentAccept.EXPECT().NumActiveL1Validators().Return(0).AnyTimes() txID := ids.GenerateTestID() utxo := &avax.UTXO{ diff --git a/vms/platformvm/block/executor/verifier.go b/vms/platformvm/block/executor/verifier.go index 1a8257c485a6..365cc5a98838 100644 --- a/vms/platformvm/block/executor/verifier.go +++ b/vms/platformvm/block/executor/verifier.go @@ -605,16 +605,16 @@ func (v *verifier) processStandardTxs(txs []*txs.Tx, feeCalculator txfee.Calcula } } - // After processing all the transactions, deactivate any SoVs that might not - // have sufficient fee to pay for the next second. + // After processing all the transactions, deactivate any L1 validators that + // might not have sufficient fee to pay for the next second. // - // This ensures that SoVs are not undercharged for the next second. - err := deactivateLowBalanceSoVs( + // This ensures that L1 validators are not undercharged for the next second. + err := deactivateLowBalanceL1Validators( v.txExecutorBackend.Config.ValidatorFeeConfig, diff, ) if err != nil { - return nil, nil, nil, 0, fmt.Errorf("failed to deactivate low balance SoVs: %w", err) + return nil, nil, nil, 0, fmt.Errorf("failed to deactivate low balance L1 validators: %w", err) } return inputs, atomicRequests, onAcceptFunc, gasConsumed, nil @@ -628,7 +628,7 @@ func calculateBlockMetrics( ) metrics.Block { var ( gasState = s.GetFeeState() - validatorExcess = s.GetSoVExcess() + validatorExcess = s.GetL1ValidatorExcess() ) return metrics.Block{ Block: blk, @@ -641,8 +641,8 @@ func calculateBlockMetrics( config.DynamicFeeConfig.ExcessConversionConstant, ), - ActiveSoVs: s.NumActiveSubnetOnlyValidators(), - ValidatorExcess: validatorExcess, + ActiveL1Validators: s.NumActiveL1Validators(), + ValidatorExcess: validatorExcess, ValidatorPrice: gas.CalculatePrice( config.ValidatorFeeConfig.MinPrice, validatorExcess, @@ -652,17 +652,17 @@ func calculateBlockMetrics( } } -// deactivateLowBalanceSoVs deactivates any SoVs that might not have sufficient -// fees to pay for the next second. -func deactivateLowBalanceSoVs( +// deactivateLowBalanceL1Validators deactivates any L1 validators that might not +// have sufficient fees to pay for the next second. +func deactivateLowBalanceL1Validators( config validatorfee.Config, diff state.Diff, ) error { var ( accruedFees = diff.GetAccruedFees() validatorFeeState = validatorfee.State{ - Current: gas.Gas(diff.NumActiveSubnetOnlyValidators()), - Excess: diff.GetSoVExcess(), + Current: gas.Gas(diff.NumActiveL1Validators()), + Excess: diff.GetL1ValidatorExcess(), } potentialCost = validatorFeeState.CostOf( config, @@ -674,35 +674,35 @@ func deactivateLowBalanceSoVs( return fmt.Errorf("could not calculate potentially accrued fees: %w", err) } - // Invariant: Proposal transactions do not impact SoV state. - sovIterator, err := diff.GetActiveSubnetOnlyValidatorsIterator() + // Invariant: Proposal transactions do not impact L1 validator state. + l1ValidatorIterator, err := diff.GetActiveL1ValidatorsIterator() if err != nil { - return fmt.Errorf("could not iterate over active SoVs: %w", err) + return fmt.Errorf("could not iterate over active L1 validators: %w", err) } - var sovsToDeactivate []state.SubnetOnlyValidator - for sovIterator.Next() { - sov := sovIterator.Value() + var l1ValidatorsToDeactivate []state.L1Validator + for l1ValidatorIterator.Next() { + l1Validator := l1ValidatorIterator.Value() // If the validator has exactly the right amount of fee for the next // second we should not remove them here. // - // GetActiveSubnetOnlyValidatorsIterator iterates in order of increasing + // GetActiveL1ValidatorsIterator iterates in order of increasing // EndAccumulatedFee, so we can break early. - if sov.EndAccumulatedFee >= potentialAccruedFees { + if l1Validator.EndAccumulatedFee >= potentialAccruedFees { break } - sovsToDeactivate = append(sovsToDeactivate, sov) + l1ValidatorsToDeactivate = append(l1ValidatorsToDeactivate, l1Validator) } // The iterator must be released prior to attempting to write to the // diff. - sovIterator.Release() + l1ValidatorIterator.Release() - for _, sov := range sovsToDeactivate { - sov.EndAccumulatedFee = 0 - if err := diff.PutSubnetOnlyValidator(sov); err != nil { - return fmt.Errorf("could not deactivate SoV %s: %w", sov.ValidationID, err) + for _, l1Validator := range l1ValidatorsToDeactivate { + l1Validator.EndAccumulatedFee = 0 + if err := diff.PutL1Validator(l1Validator); err != nil { + return fmt.Errorf("could not deactivate L1 validator %s: %w", l1Validator.ValidationID, err) } } return nil diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 36ab7fa6f251..3eba354457cc 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -500,8 +500,8 @@ func TestVerifierVisitCommitBlock(t *testing.T) { parentOnCommitState.EXPECT().GetTimestamp().Return(timestamp).Times(1), // Allow metrics to be calculated. parentOnCommitState.EXPECT().GetFeeState().Return(gas.State{}).Times(1), - parentOnCommitState.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1), - parentOnCommitState.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1), + parentOnCommitState.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1), + parentOnCommitState.EXPECT().NumActiveL1Validators().Return(0).Times(1), parentOnCommitState.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1), ) @@ -573,8 +573,8 @@ func TestVerifierVisitAbortBlock(t *testing.T) { parentOnAbortState.EXPECT().GetTimestamp().Return(timestamp).Times(1), // Allow metrics to be calculated. parentOnAbortState.EXPECT().GetFeeState().Return(gas.State{}).Times(1), - parentOnAbortState.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1), - parentOnAbortState.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1), + parentOnAbortState.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1), + parentOnAbortState.EXPECT().NumActiveL1Validators().Return(0).Times(1), parentOnAbortState.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1), ) @@ -702,9 +702,9 @@ func TestBanffAbortBlockTimestampChecks(t *testing.T) { s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(gas.State{}).Times(3) - s.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(3) + s.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(3) s.EXPECT().GetAccruedFees().Return(uint64(0)).Times(3) - s.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(3) + s.EXPECT().NumActiveL1Validators().Return(0).Times(3) onDecisionState, err := state.NewDiff(parentID, backend) require.NoError(err) @@ -802,9 +802,9 @@ func TestBanffCommitBlockTimestampChecks(t *testing.T) { s.EXPECT().GetLastAccepted().Return(parentID).Times(3) s.EXPECT().GetTimestamp().Return(parentTime).Times(3) s.EXPECT().GetFeeState().Return(gas.State{}).Times(3) - s.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(3) + s.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(3) s.EXPECT().GetAccruedFees().Return(uint64(0)).Times(3) - s.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(3) + s.EXPECT().NumActiveL1Validators().Return(0).Times(3) onDecisionState, err := state.NewDiff(parentID, backend) require.NoError(err) @@ -1217,7 +1217,7 @@ func TestBlockExecutionWithComplexity(t *testing.T) { } } -func TestDeactivateLowBalanceSoVs(t *testing.T) { +func TestDeactivateLowBalanceL1Validators(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) @@ -1225,8 +1225,8 @@ func TestDeactivateLowBalanceSoVs(t *testing.T) { pk = bls.PublicFromSecretKey(sk) pkBytes = bls.PublicKeyToUncompressedBytes(pk) - newSoV = func(endAccumulatedFee uint64) state.SubnetOnlyValidator { - return state.SubnetOnlyValidator{ + newL1Validator = func(endAccumulatedFee uint64) state.L1Validator { + return state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -1235,49 +1235,49 @@ func TestDeactivateLowBalanceSoVs(t *testing.T) { EndAccumulatedFee: endAccumulatedFee, } } - fractionalTimeSoV0 = newSoV(1 * units.NanoAvax) // lasts .5 seconds - fractionalTimeSoV1 = newSoV(1 * units.NanoAvax) // lasts .5 seconds - wholeTimeSoV = newSoV(2 * units.NanoAvax) // lasts 1 second + fractionalTimeL1Validator0 = newL1Validator(1 * units.NanoAvax) // lasts .5 seconds + fractionalTimeL1Validator1 = newL1Validator(1 * units.NanoAvax) // lasts .5 seconds + wholeTimeL1Validator = newL1Validator(2 * units.NanoAvax) // lasts 1 second ) tests := []struct { - name string - initialSoVs []state.SubnetOnlyValidator - expectedSoVs []state.SubnetOnlyValidator + name string + initialL1Validators []state.L1Validator + expectedL1Validators []state.L1Validator }{ { - name: "no SoVs", + name: "no L1 validators", }, { - name: "fractional SoV is not undercharged", - initialSoVs: []state.SubnetOnlyValidator{ - fractionalTimeSoV0, + name: "fractional L1 validator is not undercharged", + initialL1Validators: []state.L1Validator{ + fractionalTimeL1Validator0, }, }, { - name: "fractional SoVs are not undercharged", - initialSoVs: []state.SubnetOnlyValidator{ - fractionalTimeSoV0, - fractionalTimeSoV1, + name: "fractional L1 validators are not undercharged", + initialL1Validators: []state.L1Validator{ + fractionalTimeL1Validator0, + fractionalTimeL1Validator1, }, }, { - name: "whole SoVs are not overcharged", - initialSoVs: []state.SubnetOnlyValidator{ - wholeTimeSoV, + name: "whole L1 validators are not overcharged", + initialL1Validators: []state.L1Validator{ + wholeTimeL1Validator, }, - expectedSoVs: []state.SubnetOnlyValidator{ - wholeTimeSoV, + expectedL1Validators: []state.L1Validator{ + wholeTimeL1Validator, }, }, { name: "partial eviction", - initialSoVs: []state.SubnetOnlyValidator{ - fractionalTimeSoV0, - wholeTimeSoV, + initialL1Validators: []state.L1Validator{ + fractionalTimeL1Validator0, + wholeTimeL1Validator, }, - expectedSoVs: []state.SubnetOnlyValidator{ - wholeTimeSoV, + expectedL1Validators: []state.L1Validator{ + wholeTimeL1Validator, }, }, } @@ -1286,8 +1286,8 @@ func TestDeactivateLowBalanceSoVs(t *testing.T) { require := require.New(t) s := statetest.New(t, statetest.Config{}) - for _, sov := range test.initialSoVs { - require.NoError(s.PutSubnetOnlyValidator(sov)) + for _, l1Validator := range test.initialL1Validators { + require.NoError(s.PutL1Validator(l1Validator)) } diff, err := state.NewDiffOn(s) @@ -1299,13 +1299,13 @@ func TestDeactivateLowBalanceSoVs(t *testing.T) { MinPrice: gas.Price(2 * units.NanoAvax), // Min price is increased to allow fractional fees ExcessConversionConstant: genesis.LocalParams.ValidatorFeeConfig.ExcessConversionConstant, } - require.NoError(deactivateLowBalanceSoVs(config, diff)) + require.NoError(deactivateLowBalanceL1Validators(config, diff)) - sovs, err := diff.GetActiveSubnetOnlyValidatorsIterator() + l1Validators, err := diff.GetActiveL1ValidatorsIterator() require.NoError(err) require.Equal( - test.expectedSoVs, - iterator.ToSlice(sovs), + test.expectedL1Validators, + iterator.ToSlice(l1Validators), ) }) } diff --git a/vms/platformvm/block/executor/warp_verifier_test.go b/vms/platformvm/block/executor/warp_verifier_test.go index c05ffc9057eb..221224c19fdd 100644 --- a/vms/platformvm/block/executor/warp_verifier_test.go +++ b/vms/platformvm/block/executor/warp_verifier_test.go @@ -21,7 +21,7 @@ func TestVerifyWarpMessages(t *testing.T) { Unsigned: &txs.BaseTx{}, } invalidTx = &txs.Tx{ - Unsigned: &txs.RegisterSubnetValidatorTx{}, + Unsigned: &txs.RegisterL1ValidatorTx{}, } ) diff --git a/vms/platformvm/client.go b/vms/platformvm/client.go index 9507d4694d85..f19a3ce10393 100644 --- a/vms/platformvm/client.go +++ b/vms/platformvm/client.go @@ -74,9 +74,9 @@ type Client interface { GetStakingAssetID(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (ids.ID, error) // GetCurrentValidators returns the list of current validators for subnet with ID [subnetID] GetCurrentValidators(ctx context.Context, subnetID ids.ID, nodeIDs []ids.NodeID, options ...rpc.Option) ([]ClientPermissionlessValidator, error) - // GetSubnetOnlyValidator returns the requested SoV with [validationID] and + // GetL1Validator returns the requested L1 validator with [validationID] and // the height at which it was calculated. - GetSubnetOnlyValidator(ctx context.Context, validationID ids.ID, options ...rpc.Option) (SubnetOnlyValidator, uint64, error) + GetL1Validator(ctx context.Context, validationID ids.ID, options ...rpc.Option) (L1Validator, uint64, error) // GetCurrentSupply returns an upper bound on the supply of AVAX in the system along with the P-chain height GetCurrentSupply(ctx context.Context, subnetID ids.ID, options ...rpc.Option) (uint64, uint64, error) // SampleValidators returns the nodeIDs of a sample of [sampleSize] validators from the current validator set for subnet with ID [subnetID] @@ -338,9 +338,8 @@ func (c *client) GetCurrentValidators( return getClientPermissionlessValidators(res.Validators) } -// SubnetOnlyValidator is the response from calling GetSubnetOnlyValidator on -// the API client. -type SubnetOnlyValidator struct { +// L1Validator is the response from calling GetL1Validator on the API client. +type L1Validator struct { SubnetID ids.ID NodeID ids.NodeID PublicKey *bls.PublicKey @@ -349,41 +348,41 @@ type SubnetOnlyValidator struct { StartTime uint64 Weight uint64 MinNonce uint64 - // Balance is the remaining amount of AVAX this SoV has for paying the - // continuous fee. + // Balance is the remaining amount of AVAX this L1 validator has for paying + // the continuous fee. Balance uint64 } -func (c *client) GetSubnetOnlyValidator( +func (c *client) GetL1Validator( ctx context.Context, validationID ids.ID, options ...rpc.Option, -) (SubnetOnlyValidator, uint64, error) { - res := &GetSubnetOnlyValidatorReply{} - err := c.requester.SendRequest(ctx, "platform.getSubnetOnlyValidator", - &GetSubnetOnlyValidatorArgs{ +) (L1Validator, uint64, error) { + res := &GetL1ValidatorReply{} + err := c.requester.SendRequest(ctx, "platform.getL1Validator", + &GetL1ValidatorArgs{ ValidationID: validationID, }, res, options..., ) if err != nil { - return SubnetOnlyValidator{}, 0, err + return L1Validator{}, 0, err } pk, err := bls.PublicKeyFromCompressedBytes(res.PublicKey) if err != nil { - return SubnetOnlyValidator{}, 0, err + return L1Validator{}, 0, err } remainingBalanceOwnerAddrs, err := address.ParseToIDs(res.RemainingBalanceOwner.Addresses) if err != nil { - return SubnetOnlyValidator{}, 0, err + return L1Validator{}, 0, err } deactivationOwnerAddrs, err := address.ParseToIDs(res.DeactivationOwner.Addresses) if err != nil { - return SubnetOnlyValidator{}, 0, err + return L1Validator{}, 0, err } - return SubnetOnlyValidator{ + return L1Validator{ SubnetID: res.SubnetID, NodeID: res.NodeID, PublicKey: pk, @@ -669,8 +668,7 @@ func GetSubnetOwners( return subnetOwners, nil } -// GetDeactivationOwners returns a map of validation ID to subnet-only -// validation deactivation owner +// GetDeactivationOwners returns a map of validation ID to deactivation owners func GetDeactivationOwners( c Client, ctx context.Context, @@ -678,11 +676,11 @@ func GetDeactivationOwners( ) (map[ids.ID]fx.Owner, error) { deactivationOwners := make(map[ids.ID]fx.Owner, len(validationIDs)) for _, validationID := range validationIDs { - sov, _, err := c.GetSubnetOnlyValidator(ctx, validationID) + l1Validator, _, err := c.GetL1Validator(ctx, validationID) if err != nil { return nil, err } - deactivationOwners[validationID] = sov.DeactivationOwner + deactivationOwners[validationID] = l1Validator.DeactivationOwner } return deactivationOwners, nil } diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index 9d6184b3747d..2f8b149790f2 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -20,7 +20,7 @@ var Default = Config{ ChainDBCacheSize: 2048, BlockIDCacheSize: 8192, FxOwnerCacheSize: 4 * units.MiB, - SubnetConversionCacheSize: 4 * units.MiB, + SubnetToL1ConversionCacheSize: 4 * units.MiB, L1WeightsCacheSize: 16 * units.KiB, L1InactiveValidatorsCacheSize: 256 * units.KiB, L1SubnetIDNodeIDCacheSize: 16 * units.KiB, @@ -39,7 +39,7 @@ type Config struct { ChainDBCacheSize int `json:"chain-db-cache-size"` BlockIDCacheSize int `json:"block-id-cache-size"` FxOwnerCacheSize int `json:"fx-owner-cache-size"` - SubnetConversionCacheSize int `json:"subnet-conversion-cache-size"` + SubnetToL1ConversionCacheSize int `json:"subnet-to-l1-conversion-cache-size"` L1WeightsCacheSize int `json:"l1-weights-cache-size"` L1InactiveValidatorsCacheSize int `json:"l1-inactive-validators-cache-size"` L1SubnetIDNodeIDCacheSize int `json:"l1-subnet-id-node-id-cache-size"` diff --git a/vms/platformvm/config/config_test.go b/vms/platformvm/config/config_test.go index 14b9b0e4d178..07e7ae5bd43d 100644 --- a/vms/platformvm/config/config_test.go +++ b/vms/platformvm/config/config_test.go @@ -87,7 +87,7 @@ func TestConfigUnmarshal(t *testing.T) { ChainDBCacheSize: 7, BlockIDCacheSize: 8, FxOwnerCacheSize: 9, - SubnetConversionCacheSize: 10, + SubnetToL1ConversionCacheSize: 10, L1WeightsCacheSize: 11, L1InactiveValidatorsCacheSize: 12, L1SubnetIDNodeIDCacheSize: 13, diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index a5b6120cd884..23c6ee567991 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -39,7 +39,7 @@ type Block struct { GasState gas.State GasPrice gas.Price - ActiveSoVs int + ActiveL1Validators int ValidatorExcess gas.Gas ValidatorPrice gas.Price AccruedValidatorFees uint64 @@ -103,9 +103,9 @@ func New(registerer prometheus.Registerer) (Metrics, error) { Name: "gas_capacity", Help: "Minimum amount of gas that can be consumed in the next block", }), - activeSoVs: prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "active_sovs", - Help: "Number of active SoVs", + activeL1Validators: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "active_l1_validators", + Help: "Number of active L1 validators", }), excess: prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -123,7 +123,7 @@ func New(registerer prometheus.Registerer) (Metrics, error) { ), accruedValidatorFees: prometheus.NewGauge(prometheus.GaugeOpts{ Name: "accrued_validator_fees", - Help: "The total cost of running an active SoV since Etna activation", + Help: "The total cost of running an active L1 validator since Etna activation", }), validatorSetsCached: prometheus.NewCounter(prometheus.CounterOpts{ @@ -156,7 +156,7 @@ func New(registerer prometheus.Registerer) (Metrics, error) { registerer.Register(m.gasConsumed), registerer.Register(m.gasCapacity), - registerer.Register(m.activeSoVs), + registerer.Register(m.activeL1Validators), registerer.Register(m.excess), registerer.Register(m.price), registerer.Register(m.accruedValidatorFees), @@ -183,7 +183,7 @@ type metrics struct { gasConsumed prometheus.Counter gasCapacity prometheus.Gauge - activeSoVs prometheus.Gauge + activeL1Validators prometheus.Gauge excess *prometheus.GaugeVec price *prometheus.GaugeVec accruedValidatorFees prometheus.Gauge @@ -201,7 +201,7 @@ func (m *metrics) MarkAccepted(b Block) error { m.excess.With(gasLabels).Set(float64(b.GasState.Excess)) m.price.With(gasLabels).Set(float64(b.GasPrice)) - m.activeSoVs.Set(float64(b.ActiveSoVs)) + m.activeL1Validators.Set(float64(b.ActiveL1Validators)) m.excess.With(validatorsLabels).Set(float64(b.ValidatorExcess)) m.price.With(validatorsLabels).Set(float64(b.ValidatorPrice)) m.accruedValidatorFees.Set(float64(b.AccruedValidatorFees)) diff --git a/vms/platformvm/metrics/tx_metrics.go b/vms/platformvm/metrics/tx_metrics.go index b411e226c565..fe1f7eb8c01d 100644 --- a/vms/platformvm/metrics/tx_metrics.go +++ b/vms/platformvm/metrics/tx_metrics.go @@ -139,37 +139,37 @@ func (m *txMetrics) BaseTx(*txs.BaseTx) error { return nil } -func (m *txMetrics) ConvertSubnetTx(*txs.ConvertSubnetTx) error { +func (m *txMetrics) ConvertSubnetToL1Tx(*txs.ConvertSubnetToL1Tx) error { m.numTxs.With(prometheus.Labels{ - txLabel: "convert_subnet", + txLabel: "convert_subnet_to_l1", }).Inc() return nil } -func (m *txMetrics) RegisterSubnetValidatorTx(*txs.RegisterSubnetValidatorTx) error { +func (m *txMetrics) RegisterL1ValidatorTx(*txs.RegisterL1ValidatorTx) error { m.numTxs.With(prometheus.Labels{ - txLabel: "register_subnet_validator", + txLabel: "register_l1_validator", }).Inc() return nil } -func (m *txMetrics) SetSubnetValidatorWeightTx(*txs.SetSubnetValidatorWeightTx) error { +func (m *txMetrics) SetL1ValidatorWeightTx(*txs.SetL1ValidatorWeightTx) error { m.numTxs.With(prometheus.Labels{ - txLabel: "set_subnet_validator_weight", + txLabel: "set_l1_validator_weight", }).Inc() return nil } -func (m *txMetrics) IncreaseBalanceTx(*txs.IncreaseBalanceTx) error { +func (m *txMetrics) IncreaseL1ValidatorBalanceTx(*txs.IncreaseL1ValidatorBalanceTx) error { m.numTxs.With(prometheus.Labels{ - txLabel: "increase_balance", + txLabel: "increase_l1_validator_balance", }).Inc() return nil } -func (m *txMetrics) DisableSubnetValidatorTx(*txs.DisableSubnetValidatorTx) error { +func (m *txMetrics) DisableL1ValidatorTx(*txs.DisableL1ValidatorTx) error { m.numTxs.With(prometheus.Labels{ - txLabel: "disable_subnet_validator", + txLabel: "disable_l1_validator", }).Inc() return nil } diff --git a/vms/platformvm/network/warp.go b/vms/platformvm/network/warp.go index 7935eb7b6d0b..3787d92382c6 100644 --- a/vms/platformvm/network/warp.go +++ b/vms/platformvm/network/warp.go @@ -37,7 +37,7 @@ const ( ErrMismatchedValidationID ErrValidationDoesNotExist ErrValidationExists - ErrFailedToParseRegisterSubnetValidator + ErrFailedToParseRegisterL1Validator ErrValidationCouldBeRegistered ErrImpossibleNonce @@ -80,12 +80,12 @@ func (s signatureRequestVerifier) Verify( } switch payload := payloadIntf.(type) { - case *message.SubnetConversion: - return s.verifySubnetConversion(payload, justification) - case *message.SubnetValidatorRegistration: - return s.verifySubnetValidatorRegistration(payload, justification) - case *message.SubnetValidatorWeight: - return s.verifySubnetValidatorWeight(payload) + case *message.SubnetToL1Conversion: + return s.verifySubnetToL1Conversion(payload, justification) + case *message.L1ValidatorRegistration: + return s.verifyL1ValidatorRegistration(payload, justification) + case *message.L1ValidatorWeight: + return s.verifyL1ValidatorWeight(payload) default: return &common.AppError{ Code: ErrUnsupportedWarpAddressedCallPayloadType, @@ -94,8 +94,8 @@ func (s signatureRequestVerifier) Verify( } } -func (s signatureRequestVerifier) verifySubnetConversion( - msg *message.SubnetConversion, +func (s signatureRequestVerifier) verifySubnetToL1Conversion( + msg *message.SubnetToL1Conversion, justification []byte, ) *common.AppError { subnetID, err := ids.ToID(justification) @@ -109,7 +109,7 @@ func (s signatureRequestVerifier) verifySubnetConversion( s.stateLock.Lock() defer s.stateLock.Unlock() - conversion, err := s.state.GetSubnetConversion(subnetID) + conversion, err := s.state.GetSubnetToL1Conversion(subnetID) if err == database.ErrNotFound { return &common.AppError{ Code: ErrConversionDoesNotExist, @@ -133,15 +133,15 @@ func (s signatureRequestVerifier) verifySubnetConversion( return nil } -func (s signatureRequestVerifier) verifySubnetValidatorRegistration( - msg *message.SubnetValidatorRegistration, +func (s signatureRequestVerifier) verifyL1ValidatorRegistration( + msg *message.L1ValidatorRegistration, justificationBytes []byte, ) *common.AppError { if msg.Registered { - return s.verifySubnetValidatorRegistered(msg.ValidationID) + return s.verifyL1ValidatorRegistered(msg.ValidationID) } - var justification platformvm.SubnetValidatorRegistrationJustification + var justification platformvm.L1ValidatorRegistrationJustification if err := proto.Unmarshal(justificationBytes, &justification); err != nil { return &common.AppError{ Code: ErrFailedToParseJustification, @@ -150,10 +150,10 @@ func (s signatureRequestVerifier) verifySubnetValidatorRegistration( } switch preimage := justification.GetPreimage().(type) { - case *platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData: - return s.verifySubnetValidatorNotCurrentlyRegistered(msg.ValidationID, preimage.ConvertSubnetTxData) - case *platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage: - return s.verifySubnetValidatorCanNotValidate(msg.ValidationID, preimage.RegisterSubnetValidatorMessage) + case *platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData: + return s.verifySubnetValidatorNotCurrentlyRegistered(msg.ValidationID, preimage.ConvertSubnetToL1TxData) + case *platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage: + return s.verifySubnetValidatorCanNotValidate(msg.ValidationID, preimage.RegisterL1ValidatorMessage) default: return &common.AppError{ Code: ErrInvalidJustificationType, @@ -162,16 +162,16 @@ func (s signatureRequestVerifier) verifySubnetValidatorRegistration( } } -// verifySubnetValidatorRegistered verifies that the validationID is currently a +// verifyL1ValidatorRegistered verifies that the validationID is currently a // validator. -func (s signatureRequestVerifier) verifySubnetValidatorRegistered( +func (s signatureRequestVerifier) verifyL1ValidatorRegistered( validationID ids.ID, ) *common.AppError { s.stateLock.Lock() defer s.stateLock.Unlock() // Verify that the validator exists - _, err := s.state.GetSubnetOnlyValidator(validationID) + _, err := s.state.GetL1Validator(validationID) if err == database.ErrNotFound { return &common.AppError{ Code: ErrValidationDoesNotExist, @@ -181,15 +181,15 @@ func (s signatureRequestVerifier) verifySubnetValidatorRegistered( if err != nil { return &common.AppError{ Code: common.ErrUndefined.Code, - Message: "failed to get subnet only validator: " + err.Error(), + Message: "failed to get L1 validator: " + err.Error(), } } return nil } // verifySubnetValidatorNotCurrentlyRegistered verifies that the validationID -// could only correspond to a validator from a ConvertSubnetTx and that it is -// not currently a validator. +// could only correspond to a validator from a ConvertSubnetToL1Tx and that it +// is not currently a validator. func (s signatureRequestVerifier) verifySubnetValidatorNotCurrentlyRegistered( validationID ids.ID, justification *platformvm.SubnetIDIndex, @@ -214,7 +214,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorNotCurrentlyRegistered( defer s.stateLock.Unlock() // Verify that the provided subnetID has been converted. - _, err = s.state.GetSubnetConversion(subnetID) + _, err = s.state.GetSubnetToL1Conversion(subnetID) if err == database.ErrNotFound { return &common.AppError{ Code: ErrConversionDoesNotExist, @@ -229,7 +229,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorNotCurrentlyRegistered( } // Verify that the validator is not in the current state - _, err = s.state.GetSubnetOnlyValidator(validationID) + _, err = s.state.GetL1Validator(validationID) if err == nil { return &common.AppError{ Code: ErrValidationExists, @@ -239,7 +239,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorNotCurrentlyRegistered( if err != database.ErrNotFound { return &common.AppError{ Code: common.ErrUndefined.Code, - Message: "failed to lookup subnet only validator: " + err.Error(), + Message: "failed to lookup L1 validator: " + err.Error(), } } @@ -254,11 +254,11 @@ func (s signatureRequestVerifier) verifySubnetValidatorCanNotValidate( validationID ids.ID, justificationBytes []byte, ) *common.AppError { - justification, err := message.ParseRegisterSubnetValidator(justificationBytes) + justification, err := message.ParseRegisterL1Validator(justificationBytes) if err != nil { return &common.AppError{ - Code: ErrFailedToParseRegisterSubnetValidator, - Message: "failed to parse RegisterSubnetValidator justification: " + err.Error(), + Code: ErrFailedToParseRegisterL1Validator, + Message: "failed to parse RegisterL1Validator justification: " + err.Error(), } } @@ -274,7 +274,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorCanNotValidate( defer s.stateLock.Unlock() // Verify that the validator does not currently exist - _, err = s.state.GetSubnetOnlyValidator(validationID) + _, err = s.state.GetL1Validator(validationID) if err == nil { return &common.AppError{ Code: ErrValidationExists, @@ -284,7 +284,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorCanNotValidate( if err != database.ErrNotFound { return &common.AppError{ Code: common.ErrUndefined.Code, - Message: "failed to lookup subnet only validator: " + err.Error(), + Message: "failed to lookup L1 validator: " + err.Error(), } } @@ -315,8 +315,8 @@ func (s signatureRequestVerifier) verifySubnetValidatorCanNotValidate( return nil // The validator has been removed } -func (s signatureRequestVerifier) verifySubnetValidatorWeight( - msg *message.SubnetValidatorWeight, +func (s signatureRequestVerifier) verifyL1ValidatorWeight( + msg *message.L1ValidatorWeight, ) *common.AppError { if msg.Nonce == math.MaxUint64 { return &common.AppError{ @@ -328,7 +328,7 @@ func (s signatureRequestVerifier) verifySubnetValidatorWeight( s.stateLock.Lock() defer s.stateLock.Unlock() - sov, err := s.state.GetSubnetOnlyValidator(msg.ValidationID) + l1Validator, err := s.state.GetL1Validator(msg.ValidationID) switch { case err == database.ErrNotFound: return &common.AppError{ @@ -338,17 +338,17 @@ func (s signatureRequestVerifier) verifySubnetValidatorWeight( case err != nil: return &common.AppError{ Code: common.ErrUndefined.Code, - Message: "failed to get subnet only validator: " + err.Error(), + Message: "failed to get L1 validator: " + err.Error(), } - case msg.Nonce+1 != sov.MinNonce: + case msg.Nonce+1 != l1Validator.MinNonce: return &common.AppError{ Code: ErrWrongNonce, - Message: fmt.Sprintf("provided nonce %d != expected nonce (%d - 1)", msg.Nonce, sov.MinNonce), + Message: fmt.Sprintf("provided nonce %d != expected nonce (%d - 1)", msg.Nonce, l1Validator.MinNonce), } - case msg.Weight != sov.Weight: + case msg.Weight != l1Validator.Weight: return &common.AppError{ Code: ErrWrongWeight, - Message: fmt.Sprintf("provided weight %d != expected weight %d", msg.Weight, sov.Weight), + Message: fmt.Sprintf("provided weight %d != expected weight %d", msg.Weight, l1Validator.Weight), } default: return nil // The nonce and weight are correct diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index 59eba4947356..d3027c5ff61d 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -69,7 +69,7 @@ func TestSignatureRequestVerify(t *testing.T) { name: "unsupported warp addressed call payload type", payload: must[*payload.AddressedCall](t)(payload.NewAddressedCall( nil, - must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( ids.GenerateTestID(), ids.GenerateTestNodeID(), [bls.PublicKeyLen]byte{}, @@ -81,7 +81,7 @@ func TestSignatureRequestVerify(t *testing.T) { )).Bytes(), expectedErr: &common.AppError{ Code: ErrUnsupportedWarpAddressedCallPayloadType, - Message: "unsupported warp addressed call payload type: *message.RegisterSubnetValidator", + Message: "unsupported warp addressed call payload type: *message.RegisterL1Validator", }, }, } @@ -102,10 +102,10 @@ func TestSignatureRequestVerify(t *testing.T) { } } -func TestSignatureRequestVerifySubnetConversion(t *testing.T) { +func TestSignatureRequestVerifySubnetToL1Conversion(t *testing.T) { var ( subnetID = ids.GenerateTestID() - conversion = state.SubnetConversion{ + conversion = state.SubnetToL1Conversion{ ConversionID: ids.ID{1, 2, 3, 4, 5, 6, 7, 8}, ChainID: ids.GenerateTestID(), Addr: utils.RandomBytes(20), @@ -117,7 +117,7 @@ func TestSignatureRequestVerifySubnetConversion(t *testing.T) { } ) - state.SetSubnetConversion(subnetID, conversion) + state.SetSubnetToL1Conversion(subnetID, conversion) tests := []struct { name string @@ -164,7 +164,7 @@ func TestSignatureRequestVerifySubnetConversion(t *testing.T) { constants.PlatformChainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( nil, - must[*message.SubnetConversion](t)(message.NewSubnetConversion( + must[*message.SubnetToL1Conversion](t)(message.NewSubnetToL1Conversion( test.conversionID, )).Bytes(), )).Bytes(), @@ -176,12 +176,12 @@ func TestSignatureRequestVerifySubnetConversion(t *testing.T) { } } -func TestSignatureRequestVerifySubnetValidatorRegistrationRegistered(t *testing.T) { +func TestSignatureRequestVerifyL1ValidatorRegistrationRegistered(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) var ( - sov = state.SubnetOnlyValidator{ + l1Validator = state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -195,7 +195,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationRegistered(t *testing. } ) - require.NoError(t, state.PutSubnetOnlyValidator(sov)) + require.NoError(t, state.PutL1Validator(l1Validator)) tests := []struct { name string @@ -211,7 +211,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationRegistered(t *testing. }, { name: "validation exists", - validationID: sov.ValidationID, + validationID: l1Validator.ValidationID, }, } for _, test := range tests { @@ -223,7 +223,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationRegistered(t *testing. constants.PlatformChainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( nil, - must[*message.SubnetValidatorRegistration](t)(message.NewSubnetValidatorRegistration( + must[*message.L1ValidatorRegistration](t)(message.NewL1ValidatorRegistration( test.validationID, true, )).Bytes(), @@ -236,7 +236,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationRegistered(t *testing. } } -func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testing.T) { +func TestSignatureRequestVerifyL1ValidatorRegistrationNotRegistered(t *testing.T) { skBytes, err := hex.DecodeString("36a33c536d283dfa599d0a70839c67ded6c954e346c5e8e5b4794e2299907887") require.NoError(t, err) @@ -255,7 +255,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi weight uint64 = 1 ) - registerSubnetValidatorToRegister, err := message.NewRegisterSubnetValidator( + registerL1ValidatorToRegister, err := message.NewRegisterL1Validator( convertedSubnetID, nodeID0, [bls.PublicKeyLen]byte(bls.PublicKeyToCompressedBytes(pk)), @@ -266,7 +266,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi ) require.NoError(t, err) - registerSubnetValidatorNotToRegister, err := message.NewRegisterSubnetValidator( + registerL1ValidatorNotToRegister, err := message.NewRegisterL1Validator( convertedSubnetID, nodeID1, [bls.PublicKeyLen]byte(bls.PublicKeyToCompressedBytes(pk)), @@ -277,7 +277,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi ) require.NoError(t, err) - registerSubnetValidatorExpired, err := message.NewRegisterSubnetValidator( + registerL1ValidatorExpired, err := message.NewRegisterL1Validator( convertedSubnetID, nodeID2, [bls.PublicKeyLen]byte(bls.PublicKeyToCompressedBytes(pk)), @@ -288,7 +288,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi ) require.NoError(t, err) - registerSubnetValidatorToMarkExpired, err := message.NewRegisterSubnetValidator( + registerL1ValidatorToMarkExpired, err := message.NewRegisterL1Validator( convertedSubnetID, nodeID3, [bls.PublicKeyLen]byte(bls.PublicKeyToCompressedBytes(pk)), @@ -300,26 +300,26 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi require.NoError(t, err) var ( - conversion = state.SubnetConversion{} - registerSubnetValidatorValidationID = registerSubnetValidatorToRegister.ValidationID() - registerSubnetValidatorSoV = state.SubnetOnlyValidator{ - ValidationID: registerSubnetValidatorValidationID, - SubnetID: registerSubnetValidatorToRegister.SubnetID, - NodeID: ids.NodeID(registerSubnetValidatorToRegister.NodeID), + conversion = state.SubnetToL1Conversion{} + registerL1ValidatorValidationID = registerL1ValidatorToRegister.ValidationID() + registerL1ValidatorValidator = state.L1Validator{ + ValidationID: registerL1ValidatorValidationID, + SubnetID: registerL1ValidatorToRegister.SubnetID, + NodeID: ids.NodeID(registerL1ValidatorToRegister.NodeID), PublicKey: bls.PublicKeyToUncompressedBytes(pk), - Weight: registerSubnetValidatorToRegister.Weight, + Weight: registerL1ValidatorToRegister.Weight, } - convertSubnetValidatorValidationID = registerSubnetValidatorToRegister.SubnetID.Append(0) - convertSubnetValidatorSoV = state.SubnetOnlyValidator{ - ValidationID: convertSubnetValidatorValidationID, - SubnetID: registerSubnetValidatorToRegister.SubnetID, + convertSubnetToL1ValidationID = registerL1ValidatorToRegister.SubnetID.Append(0) + convertSubnetToL1Validator = state.L1Validator{ + ValidationID: convertSubnetToL1ValidationID, + SubnetID: registerL1ValidatorToRegister.SubnetID, NodeID: ids.GenerateTestNodeID(), PublicKey: bls.PublicKeyToUncompressedBytes(pk), - Weight: registerSubnetValidatorToRegister.Weight, + Weight: registerL1ValidatorToRegister.Weight, } expiryEntry = state.ExpiryEntry{ Timestamp: expiry, - ValidationID: registerSubnetValidatorToMarkExpired.ValidationID(), + ValidationID: registerL1ValidatorToMarkExpired.ValidationID(), } state = statetest.New(t, statetest.Config{}) @@ -329,9 +329,9 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi } ) - state.SetSubnetConversion(convertedSubnetID, conversion) - require.NoError(t, state.PutSubnetOnlyValidator(registerSubnetValidatorSoV)) - require.NoError(t, state.PutSubnetOnlyValidator(convertSubnetValidatorSoV)) + state.SetSubnetToL1Conversion(convertedSubnetID, conversion) + require.NoError(t, state.PutL1Validator(registerL1ValidatorValidator)) + require.NoError(t, state.PutL1Validator(convertSubnetToL1Validator)) state.PutExpiry(expiryEntry) tests := []struct { @@ -351,8 +351,8 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi { name: "failed to parse subnetID", justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{}, + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{}, }, )), expectedErr: &common.AppError{ @@ -362,11 +362,11 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi }, { name: "mismatched convert subnet validationID", - validationID: registerSubnetValidatorNotToRegister.ValidationID(), + validationID: registerL1ValidatorNotToRegister.ValidationID(), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ - ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{ + ConvertSubnetToL1TxData: &platformvm.SubnetIDIndex{ SubnetId: convertedSubnetID[:], Index: 0, }, @@ -380,11 +380,11 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi }, { name: "convert subnet validation exists", - validationID: convertSubnetValidatorValidationID, + validationID: convertSubnetToL1ValidationID, justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ - ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{ + ConvertSubnetToL1TxData: &platformvm.SubnetIDIndex{ SubnetId: convertedSubnetID[:], Index: 0, }, @@ -400,9 +400,9 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi name: "conversion does not exist", validationID: unconvertedSubnetID.Append(0), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ - ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{ + ConvertSubnetToL1TxData: &platformvm.SubnetIDIndex{ SubnetId: unconvertedSubnetID[:], Index: 0, }, @@ -418,9 +418,9 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi name: "valid convert subnet data", validationID: convertedSubnetID.Append(1), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ - ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{ + ConvertSubnetToL1TxData: &platformvm.SubnetIDIndex{ SubnetId: convertedSubnetID[:], Index: 1, }, @@ -429,24 +429,24 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi )), }, { - name: "failed to parse register subnet validator", + name: "failed to parse register L1 validator", justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{}, + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{}, }, )), expectedErr: &common.AppError{ - Code: ErrFailedToParseRegisterSubnetValidator, - Message: "failed to parse RegisterSubnetValidator justification: couldn't unpack codec version", + Code: ErrFailedToParseRegisterL1Validator, + Message: "failed to parse RegisterL1Validator justification: couldn't unpack codec version", }, }, { name: "mismatched registration validationID", - validationID: registerSubnetValidatorValidationID, + validationID: registerL1ValidatorValidationID, justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorNotToRegister.Bytes(), + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorNotToRegister.Bytes(), }, }, )), @@ -457,11 +457,11 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi }, { name: "registration validation exists", - validationID: registerSubnetValidatorValidationID, + validationID: registerL1ValidatorValidationID, justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorToRegister.Bytes(), + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorToRegister.Bytes(), }, }, )), @@ -472,22 +472,22 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi }, { name: "valid expired registration", - validationID: registerSubnetValidatorExpired.ValidationID(), + validationID: registerL1ValidatorExpired.ValidationID(), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorExpired.Bytes(), + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorExpired.Bytes(), }, }, )), }, { name: "validation could be registered", - validationID: registerSubnetValidatorNotToRegister.ValidationID(), + validationID: registerL1ValidatorNotToRegister.ValidationID(), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorNotToRegister.Bytes(), + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorNotToRegister.Bytes(), }, }, )), @@ -498,11 +498,11 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi }, { name: "validation removed", - validationID: registerSubnetValidatorToMarkExpired.ValidationID(), + validationID: registerL1ValidatorToMarkExpired.ValidationID(), justification: must[[]byte](t)(proto.Marshal( - &platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidatorToMarkExpired.Bytes(), + &platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1ValidatorToMarkExpired.Bytes(), }, }, )), @@ -524,7 +524,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi constants.PlatformChainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( nil, - must[*message.SubnetValidatorRegistration](t)(message.NewSubnetValidatorRegistration( + must[*message.L1ValidatorRegistration](t)(message.NewL1ValidatorRegistration( test.validationID, false, )).Bytes(), @@ -543,7 +543,7 @@ func TestSignatureRequestVerifySubnetValidatorRegistrationNotRegistered(t *testi } } -func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { +func TestSignatureRequestVerifyL1ValidatorWeight(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) @@ -552,7 +552,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { nonce = 10 ) var ( - sov = state.SubnetOnlyValidator{ + l1Validator = state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -568,7 +568,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { } ) - require.NoError(t, state.PutSubnetOnlyValidator(sov)) + require.NoError(t, state.PutL1Validator(l1Validator)) tests := []struct { name string @@ -594,7 +594,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { }, { name: "wrong nonce", - validationID: sov.ValidationID, + validationID: l1Validator.ValidationID, expectedErr: &common.AppError{ Code: ErrWrongNonce, Message: "provided nonce 0 != expected nonce (11 - 1)", @@ -602,7 +602,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { }, { name: "wrong weight", - validationID: sov.ValidationID, + validationID: l1Validator.ValidationID, nonce: nonce, expectedErr: &common.AppError{ Code: ErrWrongWeight, @@ -611,7 +611,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { }, { name: "valid", - validationID: sov.ValidationID, + validationID: l1Validator.ValidationID, nonce: nonce, weight: weight, }, @@ -625,7 +625,7 @@ func TestSignatureRequestVerifySubnetValidatorWeight(t *testing.T) { constants.PlatformChainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( nil, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( test.validationID, test.nonce, test.weight, diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index e5095926d2ea..14a32cd9acaa 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -507,7 +507,7 @@ func (s *Service) GetSubnet(_ *http.Request, args *GetSubnetArgs, response *GetS return err } - switch c, err := s.vm.state.GetSubnetConversion(args.SubnetID); err { + switch c, err := s.vm.state.GetSubnetToL1Conversion(args.SubnetID); err { case nil: response.IsPermissioned = false response.ConversionID = c.ConversionID @@ -985,11 +985,11 @@ func (s *Service) GetCurrentValidators(_ *http.Request, args *GetCurrentValidato return nil } -type GetSubnetOnlyValidatorArgs struct { +type GetL1ValidatorArgs struct { ValidationID ids.ID `json:"validationID"` } -type GetSubnetOnlyValidatorReply struct { +type GetL1ValidatorReply struct { SubnetID ids.ID `json:"subnetID"` NodeID ids.NodeID `json:"nodeID"` // PublicKey is the compressed BLS public key of the validator @@ -999,32 +999,32 @@ type GetSubnetOnlyValidatorReply struct { StartTime avajson.Uint64 `json:"startTime"` Weight avajson.Uint64 `json:"weight"` MinNonce avajson.Uint64 `json:"minNonce"` - // Balance is the remaining amount of AVAX this SoV has for paying the - // continuous fee, according to the last accepted state. If the validator is - // inactive, the balance will be 0. + // Balance is the remaining amount of AVAX this L1 validator has for paying + // the continuous fee, according to the last accepted state. If the + // validator is inactive, the balance will be 0. Balance avajson.Uint64 `json:"balance"` // Height is the height of the last accepted block Height avajson.Uint64 `json:"height"` } -// GetSubnetOnlyValidator returns the SoV if it exists -func (s *Service) GetSubnetOnlyValidator(r *http.Request, args *GetSubnetOnlyValidatorArgs, reply *GetSubnetOnlyValidatorReply) error { +// GetL1Validator returns the L1 validator if it exists +func (s *Service) GetL1Validator(r *http.Request, args *GetL1ValidatorArgs, reply *GetL1ValidatorReply) error { s.vm.ctx.Log.Debug("API called", zap.String("service", "platform"), - zap.String("method", "getSubnetOnlyValidator"), + zap.String("method", "getL1Validator"), zap.Stringer("validationID", args.ValidationID), ) s.vm.ctx.Lock.Lock() defer s.vm.ctx.Lock.Unlock() - sov, err := s.vm.state.GetSubnetOnlyValidator(args.ValidationID) + l1Validator, err := s.vm.state.GetL1Validator(args.ValidationID) if err != nil { - return fmt.Errorf("fetching SoV %q failed: %w", args.ValidationID, err) + return fmt.Errorf("fetching L1 validator %q failed: %w", args.ValidationID, err) } var remainingBalanceOwner message.PChainOwner - if _, err := txs.Codec.Unmarshal(sov.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { + if _, err := txs.Codec.Unmarshal(l1Validator.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { return fmt.Errorf("failed unmarshalling remaining balance owner: %w", err) } remainingBalanceAPIOwner, err := s.getAPIOwner(&secp256k1fx.OutputOwners{ @@ -1036,7 +1036,7 @@ func (s *Service) GetSubnetOnlyValidator(r *http.Request, args *GetSubnetOnlyVal } var deactivationOwner message.PChainOwner - if _, err := txs.Codec.Unmarshal(sov.DeactivationOwner, &deactivationOwner); err != nil { + if _, err := txs.Codec.Unmarshal(l1Validator.DeactivationOwner, &deactivationOwner); err != nil { return fmt.Errorf("failed unmarshalling deactivation owner: %w", err) } deactivationAPIOwner, err := s.getAPIOwner(&secp256k1fx.OutputOwners{ @@ -1053,19 +1053,19 @@ func (s *Service) GetSubnetOnlyValidator(r *http.Request, args *GetSubnetOnlyVal return fmt.Errorf("failed getting current height: %w", err) } - reply.SubnetID = sov.SubnetID - reply.NodeID = sov.NodeID + reply.SubnetID = l1Validator.SubnetID + reply.NodeID = l1Validator.NodeID reply.PublicKey = bls.PublicKeyToCompressedBytes( - bls.PublicKeyFromValidUncompressedBytes(sov.PublicKey), + bls.PublicKeyFromValidUncompressedBytes(l1Validator.PublicKey), ) reply.RemainingBalanceOwner = *remainingBalanceAPIOwner reply.DeactivationOwner = *deactivationAPIOwner - reply.StartTime = avajson.Uint64(sov.StartTime) - reply.Weight = avajson.Uint64(sov.Weight) - reply.MinNonce = avajson.Uint64(sov.MinNonce) - if sov.EndAccumulatedFee != 0 { + reply.StartTime = avajson.Uint64(l1Validator.StartTime) + reply.Weight = avajson.Uint64(l1Validator.Weight) + reply.MinNonce = avajson.Uint64(l1Validator.MinNonce) + if l1Validator.EndAccumulatedFee != 0 { accruedFees := s.vm.state.GetAccruedFees() - reply.Balance = avajson.Uint64(sov.EndAccumulatedFee - accruedFees) + reply.Balance = avajson.Uint64(l1Validator.EndAccumulatedFee - accruedFees) } reply.Height = avajson.Uint64(height) diff --git a/vms/platformvm/service.md b/vms/platformvm/service.md index fb34d57ba248..c69dafb609de 100644 --- a/vms/platformvm/service.md +++ b/vms/platformvm/service.md @@ -780,14 +780,14 @@ curl -X POST --data '{ } ``` -### `platform.getSubnetOnlyValidator` +### `platform.getL1Validator` Returns a current L1 validator. **Signature:** ```sh -platform.getSubnetOnlyValidator({ +platform.getL1Validator({ validationID: string, }) -> { subnetID: string, @@ -818,7 +818,7 @@ platform.getSubnetOnlyValidator({ - `deactivationOwner` is an `OutputOwners` which includes a `locktime`, `threshold`, and an array of `addresses`. It specifies the owner that can withdraw the balance. - `startTime` is the unix timestamp, in seconds, of when this validator was added to the validator set. - `weight` is weight of this validator used for consensus voting and ICM. -- `minNonce` is minimum nonce that must be included in a `SetSubnetValidatorWeightTx` for the transaction to be valid. +- `minNonce` is minimum nonce that must be included in a `SetL1ValidatorWeightTx` for the transaction to be valid. - `balance` is current remaining balance that can be used to pay for the validators continuous fee. - `height` is height of the last accepted block. @@ -827,7 +827,7 @@ platform.getSubnetOnlyValidator({ ```sh curl -X POST --data '{ "jsonrpc": "2.0", - "method": "platform.getSubnetOnlyValidator", + "method": "platform.getL1Validator", "params": { "validationID": ["9FAftNgNBrzHUMMApsSyV6RcFiL9UmCbvsCu28xdLV2mQ7CMo"] }, diff --git a/vms/platformvm/state/chain_time_helpers.go b/vms/platformvm/state/chain_time_helpers.go index b6d4753df984..9c665c7a7d49 100644 --- a/vms/platformvm/state/chain_time_helpers.go +++ b/vms/platformvm/state/chain_time_helpers.go @@ -80,33 +80,34 @@ func GetNextStakerChangeTime( } } - return getNextSoVEvictionTime(config, state, nextTime) + return getNextL1ValidatorEvictionTime(config, state, nextTime) } -func getNextSoVEvictionTime( +func getNextL1ValidatorEvictionTime( config validatorfee.Config, state Chain, nextTime time.Time, ) (time.Time, error) { - sovIterator, err := state.GetActiveSubnetOnlyValidatorsIterator() + l1ValidatorIterator, err := state.GetActiveL1ValidatorsIterator() if err != nil { - return time.Time{}, fmt.Errorf("could not iterate over active SoVs: %w", err) + return time.Time{}, fmt.Errorf("could not iterate over active L1 validators: %w", err) } - defer sovIterator.Release() + defer l1ValidatorIterator.Release() - // If there are no SoVs, return - if !sovIterator.Next() { + // If there are no L1 validators, return + if !l1ValidatorIterator.Next() { return nextTime, nil } // Calculate the remaining funds that the next validator to evict has. var ( - // GetActiveSubnetOnlyValidatorsIterator iterates in order of increasing - // EndAccumulatedFee, so the first SoV is the next SoV to evict. - sov = sovIterator.Value() + // GetActiveL1ValidatorsIterator iterates in order of increasing + // EndAccumulatedFee, so the first L1 validator is the next L1 validator + // to evict. + l1Validator = l1ValidatorIterator.Value() accruedFees = state.GetAccruedFees() ) - remainingFunds, err := math.Sub(sov.EndAccumulatedFee, accruedFees) + remainingFunds, err := math.Sub(l1Validator.EndAccumulatedFee, accruedFees) if err != nil { return time.Time{}, fmt.Errorf("could not calculate remaining funds: %w", err) } @@ -117,8 +118,8 @@ func getNextSoVEvictionTime( maxSeconds = uint64(nextTime.Sub(currentTime) / time.Second) ) feeState := validatorfee.State{ - Current: gas.Gas(state.NumActiveSubnetOnlyValidators()), - Excess: state.GetSoVExcess(), + Current: gas.Gas(state.NumActiveL1Validators()), + Excess: state.GetL1ValidatorExcess(), } remainingSeconds := feeState.SecondsRemaining( config, diff --git a/vms/platformvm/state/chain_time_helpers_test.go b/vms/platformvm/state/chain_time_helpers_test.go index 548b3102cbc8..7fd58dbe100f 100644 --- a/vms/platformvm/state/chain_time_helpers_test.go +++ b/vms/platformvm/state/chain_time_helpers_test.go @@ -94,11 +94,11 @@ func TestGetNextStakerChangeTime(t *testing.T) { } tests := []struct { - name string - pending []*Staker - sovs []SubnetOnlyValidator - maxTime time.Time - expected time.Time + name string + pending []*Staker + l1Validators []L1Validator + maxTime time.Time + expected time.Time }{ { name: "only current validators", @@ -124,8 +124,8 @@ func TestGetNextStakerChangeTime(t *testing.T) { expected: genesistest.DefaultValidatorStartTime.Add(time.Second), }, { - name: "subnet only validator with less than 1 second of fees", - sovs: []SubnetOnlyValidator{ + name: "L1 validator with less than 1 second of fees", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), @@ -138,8 +138,8 @@ func TestGetNextStakerChangeTime(t *testing.T) { expected: genesistest.DefaultValidatorStartTime, }, { - name: "subnet only validator with 1 second of fees", - sovs: []SubnetOnlyValidator{ + name: "L1 validator with 1 second of fees", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), @@ -152,8 +152,8 @@ func TestGetNextStakerChangeTime(t *testing.T) { expected: genesistest.DefaultValidatorStartTime.Add(time.Second), }, { - name: "subnet only validator with less than 2 seconds of fees", - sovs: []SubnetOnlyValidator{ + name: "L1 validator with less than 2 seconds of fees", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), @@ -166,8 +166,8 @@ func TestGetNextStakerChangeTime(t *testing.T) { expected: genesistest.DefaultValidatorStartTime.Add(time.Second), }, { - name: "current and subnet only validator with high balance", - sovs: []SubnetOnlyValidator{ + name: "current and L1 validator with high balance", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), @@ -194,8 +194,8 @@ func TestGetNextStakerChangeTime(t *testing.T) { for _, staker := range test.pending { require.NoError(s.PutPendingValidator(staker)) } - for _, sov := range test.sovs { - require.NoError(s.PutSubnetOnlyValidator(sov)) + for _, l1Validator := range test.l1Validators { + require.NoError(s.PutL1Validator(l1Validator)) } actual, err := GetNextStakerChangeTime( diff --git a/vms/platformvm/state/diff.go b/vms/platformvm/state/diff.go index 317e4e210142..5c882e568c5a 100644 --- a/vms/platformvm/state/diff.go +++ b/vms/platformvm/state/diff.go @@ -35,17 +35,17 @@ type diff struct { parentID ids.ID stateVersions Versions - timestamp time.Time - feeState gas.State - sovExcess gas.Gas - accruedFees uint64 - parentNumActiveSOVs int + timestamp time.Time + feeState gas.State + l1ValidatorExcess gas.Gas + accruedFees uint64 + parentNumActiveL1Validators int // Subnet ID --> supply of native asset of the subnet currentSupply map[ids.ID]uint64 - expiryDiff *expiryDiff - sovDiff *subnetOnlyValidatorsDiff + expiryDiff *expiryDiff + l1ValidatorsDiff *l1ValidatorsDiff currentStakerDiffs diffStakers // map of subnetID -> nodeID -> total accrued delegatee rewards @@ -56,7 +56,7 @@ type diff struct { // Subnet ID --> Owner of the subnet subnetOwners map[ids.ID]fx.Owner // Subnet ID --> Conversion of the subnet - subnetConversions map[ids.ID]SubnetConversion + subnetToL1Conversions map[ids.ID]SubnetToL1Conversion // Subnet ID --> Tx that transforms the subnet transformedSubnets map[ids.ID]*txs.Tx @@ -79,17 +79,17 @@ func NewDiff( return nil, fmt.Errorf("%w: %s", ErrMissingParentState, parentID) } return &diff{ - parentID: parentID, - stateVersions: stateVersions, - timestamp: parentState.GetTimestamp(), - feeState: parentState.GetFeeState(), - sovExcess: parentState.GetSoVExcess(), - accruedFees: parentState.GetAccruedFees(), - parentNumActiveSOVs: parentState.NumActiveSubnetOnlyValidators(), - expiryDiff: newExpiryDiff(), - sovDiff: newSubnetOnlyValidatorsDiff(), - subnetOwners: make(map[ids.ID]fx.Owner), - subnetConversions: make(map[ids.ID]SubnetConversion), + parentID: parentID, + stateVersions: stateVersions, + timestamp: parentState.GetTimestamp(), + feeState: parentState.GetFeeState(), + l1ValidatorExcess: parentState.GetL1ValidatorExcess(), + accruedFees: parentState.GetAccruedFees(), + parentNumActiveL1Validators: parentState.NumActiveL1Validators(), + expiryDiff: newExpiryDiff(), + l1ValidatorsDiff: newL1ValidatorsDiff(), + subnetOwners: make(map[ids.ID]fx.Owner), + subnetToL1Conversions: make(map[ids.ID]SubnetToL1Conversion), }, nil } @@ -123,12 +123,12 @@ func (d *diff) SetFeeState(feeState gas.State) { d.feeState = feeState } -func (d *diff) GetSoVExcess() gas.Gas { - return d.sovExcess +func (d *diff) GetL1ValidatorExcess() gas.Gas { + return d.l1ValidatorExcess } -func (d *diff) SetSoVExcess(excess gas.Gas) { - d.sovExcess = excess +func (d *diff) SetL1ValidatorExcess(excess gas.Gas) { + d.l1ValidatorExcess = excess } func (d *diff) GetAccruedFees() uint64 { @@ -198,26 +198,26 @@ func (d *diff) DeleteExpiry(entry ExpiryEntry) { d.expiryDiff.DeleteExpiry(entry) } -func (d *diff) GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) { +func (d *diff) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) { parentState, ok := d.stateVersions.GetState(d.parentID) if !ok { return nil, fmt.Errorf("%w: %s", ErrMissingParentState, d.parentID) } - parentIterator, err := parentState.GetActiveSubnetOnlyValidatorsIterator() + parentIterator, err := parentState.GetActiveL1ValidatorsIterator() if err != nil { return nil, err } - return d.sovDiff.getActiveSubnetOnlyValidatorsIterator(parentIterator), nil + return d.l1ValidatorsDiff.getActiveL1ValidatorsIterator(parentIterator), nil } -func (d *diff) NumActiveSubnetOnlyValidators() int { - return d.parentNumActiveSOVs + d.sovDiff.netAddedActive +func (d *diff) NumActiveL1Validators() int { + return d.parentNumActiveL1Validators + d.l1ValidatorsDiff.netAddedActive } -func (d *diff) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { - if weight, modified := d.sovDiff.modifiedTotalWeight[subnetID]; modified { +func (d *diff) WeightOfL1Validators(subnetID ids.ID) (uint64, error) { + if weight, modified := d.l1ValidatorsDiff.modifiedTotalWeight[subnetID]; modified { return weight, nil } @@ -226,27 +226,27 @@ func (d *diff) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { return 0, fmt.Errorf("%w: %s", ErrMissingParentState, d.parentID) } - return parentState.WeightOfSubnetOnlyValidators(subnetID) + return parentState.WeightOfL1Validators(subnetID) } -func (d *diff) GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { - if sov, modified := d.sovDiff.modified[validationID]; modified { - if sov.isDeleted() { - return SubnetOnlyValidator{}, database.ErrNotFound +func (d *diff) GetL1Validator(validationID ids.ID) (L1Validator, error) { + if l1Validator, modified := d.l1ValidatorsDiff.modified[validationID]; modified { + if l1Validator.isDeleted() { + return L1Validator{}, database.ErrNotFound } - return sov, nil + return l1Validator, nil } parentState, ok := d.stateVersions.GetState(d.parentID) if !ok { - return SubnetOnlyValidator{}, fmt.Errorf("%w: %s", ErrMissingParentState, d.parentID) + return L1Validator{}, fmt.Errorf("%w: %s", ErrMissingParentState, d.parentID) } - return parentState.GetSubnetOnlyValidator(validationID) + return parentState.GetL1Validator(validationID) } -func (d *diff) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { - if has, modified := d.sovDiff.hasSubnetOnlyValidator(subnetID, nodeID); modified { +func (d *diff) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { + if has, modified := d.l1ValidatorsDiff.hasL1Validator(subnetID, nodeID); modified { return has, nil } @@ -255,11 +255,11 @@ func (d *diff) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, return false, fmt.Errorf("%w: %s", ErrMissingParentState, d.parentID) } - return parentState.HasSubnetOnlyValidator(subnetID, nodeID) + return parentState.HasL1Validator(subnetID, nodeID) } -func (d *diff) PutSubnetOnlyValidator(sov SubnetOnlyValidator) error { - return d.sovDiff.putSubnetOnlyValidator(d, sov) +func (d *diff) PutL1Validator(l1Validator L1Validator) error { + return d.l1ValidatorsDiff.putL1Validator(d, l1Validator) } func (d *diff) GetCurrentValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error) { @@ -435,21 +435,21 @@ func (d *diff) SetSubnetOwner(subnetID ids.ID, owner fx.Owner) { d.subnetOwners[subnetID] = owner } -func (d *diff) GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) { - if c, ok := d.subnetConversions[subnetID]; ok { +func (d *diff) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) { + if c, ok := d.subnetToL1Conversions[subnetID]; ok { return c, nil } // If the subnet conversion was not assigned in this diff, ask the parent state. parentState, ok := d.stateVersions.GetState(d.parentID) if !ok { - return SubnetConversion{}, ErrMissingParentState + return SubnetToL1Conversion{}, ErrMissingParentState } - return parentState.GetSubnetConversion(subnetID) + return parentState.GetSubnetToL1Conversion(subnetID) } -func (d *diff) SetSubnetConversion(subnetID ids.ID, c SubnetConversion) { - d.subnetConversions[subnetID] = c +func (d *diff) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) { + d.subnetToL1Conversions[subnetID] = c } func (d *diff) GetSubnetTransformation(subnetID ids.ID) (*txs.Tx, error) { @@ -560,7 +560,7 @@ func (d *diff) DeleteUTXO(utxoID ids.ID) { func (d *diff) Apply(baseState Chain) error { baseState.SetTimestamp(d.timestamp) baseState.SetFeeState(d.feeState) - baseState.SetSoVExcess(d.sovExcess) + baseState.SetL1ValidatorExcess(d.l1ValidatorExcess) baseState.SetAccruedFees(d.accruedFees) for subnetID, supply := range d.currentSupply { baseState.SetCurrentSupply(subnetID, supply) @@ -572,23 +572,23 @@ func (d *diff) Apply(baseState Chain) error { baseState.DeleteExpiry(entry) } } - // Ensure that all sov deletions happen before any sov additions. This - // ensures that a subnetID+nodeID pair that was deleted and then re-added in - // a single diff can't get reordered into the addition happening first; - // which would return an error. - for _, sov := range d.sovDiff.modified { - if !sov.isDeleted() { + // Ensure that all l1Validator deletions happen before any l1Validator + // additions. This ensures that a subnetID+nodeID pair that was deleted and + // then re-added in a single diff can't get reordered into the addition + // happening first; which would return an error. + for _, l1Validator := range d.l1ValidatorsDiff.modified { + if !l1Validator.isDeleted() { continue } - if err := baseState.PutSubnetOnlyValidator(sov); err != nil { + if err := baseState.PutL1Validator(l1Validator); err != nil { return err } } - for _, sov := range d.sovDiff.modified { - if sov.isDeleted() { + for _, l1Validator := range d.l1ValidatorsDiff.modified { + if l1Validator.isDeleted() { continue } - if err := baseState.PutSubnetOnlyValidator(sov); err != nil { + if err := baseState.PutL1Validator(l1Validator); err != nil { return err } } @@ -672,8 +672,8 @@ func (d *diff) Apply(baseState Chain) error { for subnetID, owner := range d.subnetOwners { baseState.SetSubnetOwner(subnetID, owner) } - for subnetID, c := range d.subnetConversions { - baseState.SetSubnetConversion(subnetID, c) + for subnetID, c := range d.subnetToL1Conversions { + baseState.SetSubnetToL1Conversion(subnetID, c) } return nil } diff --git a/vms/platformvm/state/diff_test.go b/vms/platformvm/state/diff_test.go index 9cc67ff8d9ef..a1019d5123a0 100644 --- a/vms/platformvm/state/diff_test.go +++ b/vms/platformvm/state/diff_test.go @@ -69,7 +69,7 @@ func TestDiffFeeState(t *testing.T) { assertChainsEqual(t, state, d) } -func TestDiffSoVExcess(t *testing.T) { +func TestDiffL1ValidatorExcess(t *testing.T) { require := require.New(t) state := newTestState(t, memdb.New()) @@ -77,11 +77,11 @@ func TestDiffSoVExcess(t *testing.T) { d, err := NewDiffOn(state) require.NoError(err) - initialExcess := state.GetSoVExcess() + initialExcess := state.GetL1ValidatorExcess() newExcess := initialExcess + 1 - d.SetSoVExcess(newExcess) - require.Equal(newExcess, d.GetSoVExcess()) - require.Equal(initialExcess, state.GetSoVExcess()) + d.SetL1ValidatorExcess(newExcess) + require.Equal(newExcess, d.GetL1ValidatorExcess()) + require.Equal(initialExcess, state.GetL1ValidatorExcess()) require.NoError(d.Apply(state)) assertChainsEqual(t, state, d) @@ -283,8 +283,8 @@ func TestDiffExpiry(t *testing.T) { } } -func TestDiffSubnetOnlyValidatorsErrors(t *testing.T) { - sov := SubnetOnlyValidator{ +func TestDiffL1ValidatorsErrors(t *testing.T) { + l1Validator := L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -294,53 +294,53 @@ func TestDiffSubnetOnlyValidatorsErrors(t *testing.T) { tests := []struct { name string initialEndAccumulatedFee uint64 - sov SubnetOnlyValidator + l1Validator L1Validator expectedErr error }{ { name: "mutate active constants", initialEndAccumulatedFee: 1, - sov: SubnetOnlyValidator{ - ValidationID: sov.ValidationID, + l1Validator: L1Validator{ + ValidationID: l1Validator.ValidationID, NodeID: ids.GenerateTestNodeID(), }, - expectedErr: ErrMutatedSubnetOnlyValidator, + expectedErr: ErrMutatedL1Validator, }, { name: "mutate inactive constants", initialEndAccumulatedFee: 0, - sov: SubnetOnlyValidator{ - ValidationID: sov.ValidationID, + l1Validator: L1Validator{ + ValidationID: l1Validator.ValidationID, NodeID: ids.GenerateTestNodeID(), }, - expectedErr: ErrMutatedSubnetOnlyValidator, + expectedErr: ErrMutatedL1Validator, }, { name: "conflicting legacy subnetID and nodeID pair", initialEndAccumulatedFee: 1, - sov: SubnetOnlyValidator{ + l1Validator: L1Validator{ ValidationID: ids.GenerateTestID(), NodeID: defaultValidatorNodeID, }, - expectedErr: ErrConflictingSubnetOnlyValidator, + expectedErr: ErrConflictingL1Validator, }, { name: "duplicate active subnetID and nodeID pair", initialEndAccumulatedFee: 1, - sov: SubnetOnlyValidator{ + l1Validator: L1Validator{ ValidationID: ids.GenerateTestID(), - NodeID: sov.NodeID, + NodeID: l1Validator.NodeID, }, - expectedErr: ErrDuplicateSubnetOnlyValidator, + expectedErr: ErrDuplicateL1Validator, }, { name: "duplicate inactive subnetID and nodeID pair", initialEndAccumulatedFee: 0, - sov: SubnetOnlyValidator{ + l1Validator: L1Validator{ ValidationID: ids.GenerateTestID(), - NodeID: sov.NodeID, + NodeID: l1Validator.NodeID, }, - expectedErr: ErrDuplicateSubnetOnlyValidator, + expectedErr: ErrDuplicateL1Validator, }, } @@ -352,22 +352,22 @@ func TestDiffSubnetOnlyValidatorsErrors(t *testing.T) { require.NoError(state.PutCurrentValidator(&Staker{ TxID: ids.GenerateTestID(), - SubnetID: sov.SubnetID, + SubnetID: l1Validator.SubnetID, NodeID: defaultValidatorNodeID, })) - sov.EndAccumulatedFee = test.initialEndAccumulatedFee - require.NoError(state.PutSubnetOnlyValidator(sov)) + l1Validator.EndAccumulatedFee = test.initialEndAccumulatedFee + require.NoError(state.PutL1Validator(l1Validator)) d, err := NewDiffOn(state) require.NoError(err) // Initialize subnetID, weight, and endAccumulatedFee as they are // constant among all tests. - test.sov.SubnetID = sov.SubnetID - test.sov.Weight = 1 // Not removed - test.sov.EndAccumulatedFee = rand.Uint64() //#nosec G404 - err = d.PutSubnetOnlyValidator(test.sov) + test.l1Validator.SubnetID = l1Validator.SubnetID + test.l1Validator.Weight = 1 // Not removed + test.l1Validator.EndAccumulatedFee = rand.Uint64() //#nosec G404 + err = d.PutL1Validator(test.l1Validator) require.ErrorIs(err, test.expectedErr) // The invalid addition should not have modified the diff. @@ -384,9 +384,9 @@ func TestDiffCurrentValidator(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -421,9 +421,9 @@ func TestDiffPendingValidator(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -464,9 +464,9 @@ func TestDiffCurrentDelegator(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -510,9 +510,9 @@ func TestDiffPendingDelegator(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -650,9 +650,9 @@ func TestDiffTx(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -750,9 +750,9 @@ func TestDiffUTXO(t *testing.T) { // Called in NewDiffOn state.EXPECT().GetTimestamp().Return(time.Now()).Times(1) state.EXPECT().GetFeeState().Return(gas.State{}).Times(1) - state.EXPECT().GetSoVExcess().Return(gas.Gas(0)).Times(1) + state.EXPECT().GetL1ValidatorExcess().Return(gas.Gas(0)).Times(1) state.EXPECT().GetAccruedFees().Return(uint64(0)).Times(1) - state.EXPECT().NumActiveSubnetOnlyValidators().Return(0).Times(1) + state.EXPECT().NumActiveL1Validators().Return(0).Times(1) d, err := NewDiffOn(state) require.NoError(err) @@ -807,17 +807,17 @@ func assertChainsEqual(t *testing.T, expected, actual Chain) { ) } - expectedActiveSOVsIterator, expectedErr := expected.GetActiveSubnetOnlyValidatorsIterator() - actualActiveSOVsIterator, actualErr := actual.GetActiveSubnetOnlyValidatorsIterator() + expectedActiveL1ValidatorsIterator, expectedErr := expected.GetActiveL1ValidatorsIterator() + actualActiveL1ValidatorsIterator, actualErr := actual.GetActiveL1ValidatorsIterator() require.Equal(expectedErr, actualErr) if expectedErr == nil { require.Equal( - iterator.ToSlice(expectedActiveSOVsIterator), - iterator.ToSlice(actualActiveSOVsIterator), + iterator.ToSlice(expectedActiveL1ValidatorsIterator), + iterator.ToSlice(actualActiveL1ValidatorsIterator), ) } - require.Equal(expected.NumActiveSubnetOnlyValidators(), actual.NumActiveSubnetOnlyValidators()) + require.Equal(expected.NumActiveL1Validators(), actual.NumActiveL1Validators()) expectedCurrentStakerIterator, expectedErr := expected.GetCurrentStakerIterator() actualCurrentStakerIterator, actualErr := actual.GetCurrentStakerIterator() @@ -841,7 +841,7 @@ func assertChainsEqual(t *testing.T, expected, actual Chain) { require.Equal(expected.GetTimestamp(), actual.GetTimestamp()) require.Equal(expected.GetFeeState(), actual.GetFeeState()) - require.Equal(expected.GetSoVExcess(), actual.GetSoVExcess()) + require.Equal(expected.GetL1ValidatorExcess(), actual.GetL1ValidatorExcess()) require.Equal(expected.GetAccruedFees(), actual.GetAccruedFees()) expectedCurrentSupply, err := expected.GetCurrentSupply(constants.PrimaryNetworkID) @@ -911,42 +911,42 @@ func TestDiffSubnetOwner(t *testing.T) { require.Equal(owner2, owner) } -func TestDiffSubnetConversion(t *testing.T) { +func TestDiffSubnetToL1Conversion(t *testing.T) { var ( require = require.New(t) state = newTestState(t, memdb.New()) subnetID = ids.GenerateTestID() - expectedConversion = SubnetConversion{ + expectedConversion = SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: []byte{1, 2, 3, 4}, } ) - actualConversion, err := state.GetSubnetConversion(subnetID) + actualConversion, err := state.GetSubnetToL1Conversion(subnetID) require.ErrorIs(err, database.ErrNotFound) require.Zero(actualConversion) d, err := NewDiffOn(state) require.NoError(err) - actualConversion, err = d.GetSubnetConversion(subnetID) + actualConversion, err = d.GetSubnetToL1Conversion(subnetID) require.ErrorIs(err, database.ErrNotFound) require.Zero(actualConversion) // Setting a subnet conversion should be reflected on diff not state - d.SetSubnetConversion(subnetID, expectedConversion) - actualConversion, err = d.GetSubnetConversion(subnetID) + d.SetSubnetToL1Conversion(subnetID, expectedConversion) + actualConversion, err = d.GetSubnetToL1Conversion(subnetID) require.NoError(err) require.Equal(expectedConversion, actualConversion) - actualConversion, err = state.GetSubnetConversion(subnetID) + actualConversion, err = state.GetSubnetToL1Conversion(subnetID) require.ErrorIs(err, database.ErrNotFound) require.Zero(actualConversion) // State should reflect new subnet conversion after diff is applied require.NoError(d.Apply(state)) - actualConversion, err = state.GetSubnetConversion(subnetID) + actualConversion, err = state.GetSubnetToL1Conversion(subnetID) require.NoError(err) require.Equal(expectedConversion, actualConversion) } diff --git a/vms/platformvm/state/l1_validator.go b/vms/platformvm/state/l1_validator.go new file mode 100644 index 000000000000..3f728f993ce4 --- /dev/null +++ b/vms/platformvm/state/l1_validator.go @@ -0,0 +1,437 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package state + +import ( + "bytes" + "errors" + "fmt" + + "github.com/google/btree" + + "github.com/ava-labs/avalanchego/cache" + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/iterator" + "github.com/ava-labs/avalanchego/utils/math" + "github.com/ava-labs/avalanchego/utils/maybe" + "github.com/ava-labs/avalanchego/vms/platformvm/block" +) + +var ( + _ btree.LessFunc[L1Validator] = L1Validator.Less + _ utils.Sortable[L1Validator] = L1Validator{} + + ErrMutatedL1Validator = errors.New("L1 validator contains mutated constant fields") + ErrConflictingL1Validator = errors.New("L1 validator contains conflicting subnetID + nodeID pair") + ErrDuplicateL1Validator = errors.New("L1 validator contains duplicate subnetID + nodeID pair") +) + +type L1Validators interface { + // GetActiveL1ValidatorsIterator returns an iterator of all the active L1 + // validators in increasing order of EndAccumulatedFee. + // + // It is the caller's responsibility to call [Release] on the iterator after + // use. + // + // It is not guaranteed to be safe to modify the state while using the + // iterator. After releasing the iterator, the state may be safely modified. + GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) + + // NumActiveL1Validators returns the number of currently active L1 + // validators. + NumActiveL1Validators() int + + // WeightOfL1Validators returns the total active and inactive weight of L1 + // validators on [subnetID]. + WeightOfL1Validators(subnetID ids.ID) (uint64, error) + + // GetL1Validator returns the validator with [validationID] if it exists. If + // the validator does not exist, [err] will equal [database.ErrNotFound]. + GetL1Validator(validationID ids.ID) (L1Validator, error) + + // HasL1Validator returns the validator with [validationID] if it exists. + HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) + + // PutL1Validator inserts [l1Validator] as a validator. If the weight of the + // validator is 0, the validator is removed. + // + // If inserting this validator attempts to modify any of the constant fields + // of the L1 validator struct, an error will be returned. + // + // If inserting this validator would cause the total weight of L1 validators + // on a subnet to overflow MaxUint64, an error will be returned. + // + // If inserting this validator would cause there to be multiple validators + // with the same subnetID and nodeID pair to exist at the same time, an + // error will be returned. + // + // If an L1 validator is added with the same validationID as a previously + // removed L1 validator, the behavior is undefined. + PutL1Validator(l1Validator L1Validator) error +} + +// L1Validator defines an ACP-77 validator. For a given ValidationID, it is +// expected for SubnetID, NodeID, PublicKey, RemainingBalanceOwner, +// DeactivationOwner, and StartTime to be constant. +type L1Validator struct { + // ValidationID is not serialized because it is used as the key in the + // database, so it doesn't need to be stored in the value. + ValidationID ids.ID + + SubnetID ids.ID `serialize:"true"` + NodeID ids.NodeID `serialize:"true"` + + // PublicKey is the uncompressed BLS public key of the validator. It is + // guaranteed to be populated. + PublicKey []byte `serialize:"true"` + + // RemainingBalanceOwner is the owner that will be used when returning the + // balance of the validator after removing accrued fees. + RemainingBalanceOwner []byte `serialize:"true"` + + // DeactivationOwner is the owner that can manually deactivate the + // validator. + DeactivationOwner []byte `serialize:"true"` + + // StartTime is the unix timestamp, in seconds, when this validator was + // added to the set. + StartTime uint64 `serialize:"true"` + + // Weight of this validator. It can be updated when the MinNonce is + // increased. If the weight is being set to 0, the validator is being + // removed. + Weight uint64 `serialize:"true"` + + // MinNonce is the smallest nonce that can be used to modify this + // validator's weight. It is initially set to 0 and is set to one higher + // than the last nonce used. It is not valid to use nonce MaxUint64 unless + // the weight is being set to 0, which removes the validator from the set. + MinNonce uint64 `serialize:"true"` + + // EndAccumulatedFee is the amount of accumulated fees per validator that + // can accrue before this validator must be deactivated. It is equal to the + // amount of fees this validator is willing to pay plus the total amount of + // fees a validator would have needed to pay from the activation of the Etna + // upgrade until this validator was registered. Note that this relies on the + // fact that every validator is charged the same fee for each unit of time. + // + // If this value is 0, the validator is inactive. + EndAccumulatedFee uint64 `serialize:"true"` +} + +func (v L1Validator) Less(o L1Validator) bool { + return v.Compare(o) == -1 +} + +// Compare determines a canonical ordering of L1 validators based on their +// EndAccumulatedFees and ValidationIDs. Lower EndAccumulatedFees result in an +// earlier ordering. +func (v L1Validator) Compare(o L1Validator) int { + switch { + case v.EndAccumulatedFee < o.EndAccumulatedFee: + return -1 + case o.EndAccumulatedFee < v.EndAccumulatedFee: + return 1 + default: + return v.ValidationID.Compare(o.ValidationID) + } +} + +// immutableFieldsAreUnmodified returns true if two versions of the same +// validator are valid. Either because the validationID has changed or because +// no unexpected fields have been modified. +func (v L1Validator) immutableFieldsAreUnmodified(o L1Validator) bool { + if v.ValidationID != o.ValidationID { + return true + } + return v.SubnetID == o.SubnetID && + v.NodeID == o.NodeID && + bytes.Equal(v.PublicKey, o.PublicKey) && + bytes.Equal(v.RemainingBalanceOwner, o.RemainingBalanceOwner) && + bytes.Equal(v.DeactivationOwner, o.DeactivationOwner) && + v.StartTime == o.StartTime +} + +func (v L1Validator) isDeleted() bool { + return v.Weight == 0 +} + +func (v L1Validator) isActive() bool { + return v.Weight != 0 && v.EndAccumulatedFee != 0 +} + +func (v L1Validator) effectiveValidationID() ids.ID { + if v.isActive() { + return v.ValidationID + } + return ids.Empty +} + +func (v L1Validator) effectiveNodeID() ids.NodeID { + if v.isActive() { + return v.NodeID + } + return ids.EmptyNodeID +} + +func (v L1Validator) effectivePublicKey() *bls.PublicKey { + if v.isActive() { + return bls.PublicKeyFromValidUncompressedBytes(v.PublicKey) + } + return nil +} + +func (v L1Validator) effectivePublicKeyBytes() []byte { + if v.isActive() { + return v.PublicKey + } + return nil +} + +func getL1Validator( + cache cache.Cacher[ids.ID, maybe.Maybe[L1Validator]], + db database.KeyValueReader, + validationID ids.ID, +) (L1Validator, error) { + if maybeL1Validator, ok := cache.Get(validationID); ok { + if maybeL1Validator.IsNothing() { + return L1Validator{}, database.ErrNotFound + } + return maybeL1Validator.Value(), nil + } + + bytes, err := db.Get(validationID[:]) + if err == database.ErrNotFound { + cache.Put(validationID, maybe.Nothing[L1Validator]()) + return L1Validator{}, database.ErrNotFound + } + if err != nil { + return L1Validator{}, err + } + + l1Validator := L1Validator{ + ValidationID: validationID, + } + if _, err := block.GenesisCodec.Unmarshal(bytes, &l1Validator); err != nil { + return L1Validator{}, fmt.Errorf("failed to unmarshal L1 validator: %w", err) + } + + cache.Put(validationID, maybe.Some(l1Validator)) + return l1Validator, nil +} + +func putL1Validator( + db database.KeyValueWriter, + cache cache.Cacher[ids.ID, maybe.Maybe[L1Validator]], + l1Validator L1Validator, +) error { + bytes, err := block.GenesisCodec.Marshal(block.CodecVersion, l1Validator) + if err != nil { + return fmt.Errorf("failed to marshal L1 validator: %w", err) + } + if err := db.Put(l1Validator.ValidationID[:], bytes); err != nil { + return err + } + + cache.Put(l1Validator.ValidationID, maybe.Some(l1Validator)) + return nil +} + +func deleteL1Validator( + db database.KeyValueDeleter, + cache cache.Cacher[ids.ID, maybe.Maybe[L1Validator]], + validationID ids.ID, +) error { + if err := db.Delete(validationID[:]); err != nil { + return err + } + + cache.Put(validationID, maybe.Nothing[L1Validator]()) + return nil +} + +type l1ValidatorsDiff struct { + netAddedActive int // May be negative + modifiedTotalWeight map[ids.ID]uint64 // subnetID -> totalWeight + modified map[ids.ID]L1Validator + modifiedHasNodeIDs map[subnetIDNodeID]bool + active *btree.BTreeG[L1Validator] +} + +func newL1ValidatorsDiff() *l1ValidatorsDiff { + return &l1ValidatorsDiff{ + modifiedTotalWeight: make(map[ids.ID]uint64), + modified: make(map[ids.ID]L1Validator), + modifiedHasNodeIDs: make(map[subnetIDNodeID]bool), + active: btree.NewG(defaultTreeDegree, L1Validator.Less), + } +} + +// getActiveL1ValidatorsIterator takes in the parent iterator, removes all +// modified validators, and then adds all modified active validators. +func (d *l1ValidatorsDiff) getActiveL1ValidatorsIterator(parentIterator iterator.Iterator[L1Validator]) iterator.Iterator[L1Validator] { + return iterator.Merge( + L1Validator.Less, + iterator.Filter(parentIterator, func(l1Validator L1Validator) bool { + _, ok := d.modified[l1Validator.ValidationID] + return ok + }), + iterator.FromTree(d.active), + ) +} + +func (d *l1ValidatorsDiff) hasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, bool) { + subnetIDNodeID := subnetIDNodeID{ + subnetID: subnetID, + nodeID: nodeID, + } + has, modified := d.modifiedHasNodeIDs[subnetIDNodeID] + return has, modified +} + +func (d *l1ValidatorsDiff) putL1Validator(state Chain, l1Validator L1Validator) error { + var ( + prevWeight uint64 + prevActive bool + newActive = l1Validator.isActive() + ) + switch priorL1Validator, err := state.GetL1Validator(l1Validator.ValidationID); err { + case nil: + if !priorL1Validator.immutableFieldsAreUnmodified(l1Validator) { + return ErrMutatedL1Validator + } + + prevWeight = priorL1Validator.Weight + prevActive = priorL1Validator.isActive() + case database.ErrNotFound: + // Verify that there is not a legacy subnet validator with the same + // subnetID+nodeID as this L1 validator. + _, err := state.GetCurrentValidator(l1Validator.SubnetID, l1Validator.NodeID) + if err == nil { + return ErrConflictingL1Validator + } + if err != database.ErrNotFound { + return err + } + + has, err := state.HasL1Validator(l1Validator.SubnetID, l1Validator.NodeID) + if err != nil { + return err + } + if has { + return ErrDuplicateL1Validator + } + default: + return err + } + + if prevWeight != l1Validator.Weight { + weight, err := state.WeightOfL1Validators(l1Validator.SubnetID) + if err != nil { + return err + } + + weight, err = math.Sub(weight, prevWeight) + if err != nil { + return err + } + weight, err = math.Add(weight, l1Validator.Weight) + if err != nil { + return err + } + + d.modifiedTotalWeight[l1Validator.SubnetID] = weight + } + + switch { + case prevActive && !newActive: + d.netAddedActive-- + case !prevActive && newActive: + d.netAddedActive++ + } + + if prevL1Validator, ok := d.modified[l1Validator.ValidationID]; ok { + d.active.Delete(prevL1Validator) + } + d.modified[l1Validator.ValidationID] = l1Validator + + subnetIDNodeID := subnetIDNodeID{ + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.NodeID, + } + d.modifiedHasNodeIDs[subnetIDNodeID] = !l1Validator.isDeleted() + if l1Validator.isActive() { + d.active.ReplaceOrInsert(l1Validator) + } + return nil +} + +type activeL1Validators struct { + lookup map[ids.ID]L1Validator + tree *btree.BTreeG[L1Validator] +} + +func newActiveL1Validators() *activeL1Validators { + return &activeL1Validators{ + lookup: make(map[ids.ID]L1Validator), + tree: btree.NewG(defaultTreeDegree, L1Validator.Less), + } +} + +func (a *activeL1Validators) get(validationID ids.ID) (L1Validator, bool) { + l1Validator, ok := a.lookup[validationID] + return l1Validator, ok +} + +func (a *activeL1Validators) put(l1Validator L1Validator) { + a.lookup[l1Validator.ValidationID] = l1Validator + a.tree.ReplaceOrInsert(l1Validator) +} + +func (a *activeL1Validators) delete(validationID ids.ID) bool { + l1Validator, ok := a.lookup[validationID] + if !ok { + return false + } + + delete(a.lookup, validationID) + a.tree.Delete(l1Validator) + return true +} + +func (a *activeL1Validators) len() int { + return len(a.lookup) +} + +func (a *activeL1Validators) newIterator() iterator.Iterator[L1Validator] { + return iterator.FromTree(a.tree) +} + +func (a *activeL1Validators) addStakersToValidatorManager(vdrs validators.Manager) error { + for validationID, l1Validator := range a.lookup { + pk := bls.PublicKeyFromValidUncompressedBytes(l1Validator.PublicKey) + if err := vdrs.AddStaker(l1Validator.SubnetID, l1Validator.NodeID, pk, validationID, l1Validator.Weight); err != nil { + return err + } + } + return nil +} + +func addL1ValidatorToValidatorManager(vdrs validators.Manager, l1Validator L1Validator) error { + nodeID := l1Validator.effectiveNodeID() + if vdrs.GetWeight(l1Validator.SubnetID, nodeID) != 0 { + return vdrs.AddWeight(l1Validator.SubnetID, nodeID, l1Validator.Weight) + } + return vdrs.AddStaker( + l1Validator.SubnetID, + nodeID, + l1Validator.effectivePublicKey(), + l1Validator.effectiveValidationID(), + l1Validator.Weight, + ) +} diff --git a/vms/platformvm/state/l1_validator_test.go b/vms/platformvm/state/l1_validator_test.go new file mode 100644 index 000000000000..96fd968abccc --- /dev/null +++ b/vms/platformvm/state/l1_validator_test.go @@ -0,0 +1,246 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package state + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/cache" + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/maybe" + "github.com/ava-labs/avalanchego/vms/platformvm/block" +) + +func TestL1Validator_Compare(t *testing.T) { + tests := []struct { + name string + v L1Validator + o L1Validator + expected int + }{ + { + name: "v.EndAccumulatedFee < o.EndAccumulatedFee", + v: L1Validator{ + ValidationID: ids.GenerateTestID(), + EndAccumulatedFee: 1, + }, + o: L1Validator{ + ValidationID: ids.GenerateTestID(), + EndAccumulatedFee: 2, + }, + expected: -1, + }, + { + name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID < o.ValidationID", + v: L1Validator{ + ValidationID: ids.ID{0}, + EndAccumulatedFee: 1, + }, + o: L1Validator{ + ValidationID: ids.ID{1}, + EndAccumulatedFee: 1, + }, + expected: -1, + }, + { + name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID = o.ValidationID", + v: L1Validator{ + ValidationID: ids.ID{0}, + EndAccumulatedFee: 1, + }, + o: L1Validator{ + ValidationID: ids.ID{0}, + EndAccumulatedFee: 1, + }, + expected: 0, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require := require.New(t) + + require.Equal(test.expected, test.v.Compare(test.o)) + require.Equal(-test.expected, test.o.Compare(test.v)) + require.Equal(test.expected == -1, test.v.Less(test.o)) + require.False(test.o.Less(test.v)) + }) + } +} + +func TestL1Validator_immutableFieldsAreUnmodified(t *testing.T) { + var ( + randomizeL1Validator = func(l1Validator L1Validator) L1Validator { + // Randomize unrelated fields + l1Validator.Weight = rand.Uint64() // #nosec G404 + l1Validator.MinNonce = rand.Uint64() // #nosec G404 + l1Validator.EndAccumulatedFee = rand.Uint64() // #nosec G404 + return l1Validator + } + l1Validator = newL1Validator() + ) + + t.Run("equal", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + require.True(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("everything is different", func(t *testing.T) { + v := randomizeL1Validator(newL1Validator()) + require.True(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different subnetID", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.SubnetID = ids.GenerateTestID() + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different nodeID", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.NodeID = ids.GenerateTestNodeID() + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different publicKey", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.PublicKey = utils.RandomBytes(bls.PublicKeyLen) + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different remainingBalanceOwner", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.RemainingBalanceOwner = utils.RandomBytes(32) + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different deactivationOwner", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.DeactivationOwner = utils.RandomBytes(32) + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) + t.Run("different startTime", func(t *testing.T) { + v := randomizeL1Validator(l1Validator) + v.StartTime = rand.Uint64() // #nosec G404 + require.False(t, l1Validator.immutableFieldsAreUnmodified(v)) + }) +} + +func TestGetL1Validator(t *testing.T) { + var ( + l1Validator = newL1Validator() + dbWithL1Validator = memdb.New() + dbWithoutL1Validator = memdb.New() + cacheWithL1Validator = &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10} + cacheWithoutL1Validator = &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10} + ) + + require.NoError(t, putL1Validator(dbWithL1Validator, cacheWithL1Validator, l1Validator)) + require.NoError(t, deleteL1Validator(dbWithoutL1Validator, cacheWithoutL1Validator, l1Validator.ValidationID)) + + tests := []struct { + name string + cache cache.Cacher[ids.ID, maybe.Maybe[L1Validator]] + db database.KeyValueReader + expectedL1Validator L1Validator + expectedErr error + expectedEntry maybe.Maybe[L1Validator] + }{ + { + name: "cached with validator", + cache: cacheWithL1Validator, + db: dbWithoutL1Validator, + expectedL1Validator: l1Validator, + expectedEntry: maybe.Some(l1Validator), + }, + { + name: "from disk with validator", + cache: &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10}, + db: dbWithL1Validator, + expectedL1Validator: l1Validator, + expectedEntry: maybe.Some(l1Validator), + }, + { + name: "cached without validator", + cache: cacheWithoutL1Validator, + db: dbWithL1Validator, + expectedErr: database.ErrNotFound, + }, + { + name: "from disk without validator", + cache: &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10}, + db: dbWithoutL1Validator, + expectedErr: database.ErrNotFound, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require := require.New(t) + + gotL1Validator, err := getL1Validator(test.cache, test.db, l1Validator.ValidationID) + require.ErrorIs(err, test.expectedErr) + require.Equal(test.expectedL1Validator, gotL1Validator) + + cachedL1Validator, ok := test.cache.Get(l1Validator.ValidationID) + require.True(ok) + require.Equal(test.expectedEntry, cachedL1Validator) + }) + } +} + +func TestPutL1Validator(t *testing.T) { + var ( + require = require.New(t) + l1Validator = newL1Validator() + db = memdb.New() + cache = &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10} + ) + expectedL1ValidatorBytes, err := block.GenesisCodec.Marshal(block.CodecVersion, l1Validator) + require.NoError(err) + + require.NoError(putL1Validator(db, cache, l1Validator)) + + l1ValidatorBytes, err := db.Get(l1Validator.ValidationID[:]) + require.NoError(err) + require.Equal(expectedL1ValidatorBytes, l1ValidatorBytes) + + l1ValidatorFromCache, ok := cache.Get(l1Validator.ValidationID) + require.True(ok) + require.Equal(maybe.Some(l1Validator), l1ValidatorFromCache) +} + +func TestDeleteL1Validator(t *testing.T) { + var ( + require = require.New(t) + validationID = ids.GenerateTestID() + db = memdb.New() + cache = &cache.LRU[ids.ID, maybe.Maybe[L1Validator]]{Size: 10} + ) + require.NoError(db.Put(validationID[:], nil)) + + require.NoError(deleteL1Validator(db, cache, validationID)) + + hasL1Validator, err := db.Has(validationID[:]) + require.NoError(err) + require.False(hasL1Validator) + + l1ValidatorFromCache, ok := cache.Get(validationID) + require.True(ok) + require.Equal(maybe.Nothing[L1Validator](), l1ValidatorFromCache) +} + +func newL1Validator() L1Validator { + return L1Validator{ + ValidationID: ids.GenerateTestID(), + SubnetID: ids.GenerateTestID(), + NodeID: ids.GenerateTestNodeID(), + PublicKey: utils.RandomBytes(bls.PublicKeyLen), + RemainingBalanceOwner: utils.RandomBytes(32), + DeactivationOwner: utils.RandomBytes(32), + StartTime: rand.Uint64(), // #nosec G404 + Weight: rand.Uint64(), // #nosec G404 + MinNonce: rand.Uint64(), // #nosec G404 + EndAccumulatedFee: rand.Uint64(), // #nosec G404 + } +} diff --git a/vms/platformvm/state/mock_chain.go b/vms/platformvm/state/mock_chain.go index 5a6d21b2dd12..0c629e524cf3 100644 --- a/vms/platformvm/state/mock_chain.go +++ b/vms/platformvm/state/mock_chain.go @@ -204,19 +204,19 @@ func (mr *MockChainMockRecorder) GetAccruedFees() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccruedFees", reflect.TypeOf((*MockChain)(nil).GetAccruedFees)) } -// GetActiveSubnetOnlyValidatorsIterator mocks base method. -func (m *MockChain) GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) { +// GetActiveL1ValidatorsIterator mocks base method. +func (m *MockChain) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetActiveSubnetOnlyValidatorsIterator") - ret0, _ := ret[0].(iterator.Iterator[SubnetOnlyValidator]) + ret := m.ctrl.Call(m, "GetActiveL1ValidatorsIterator") + ret0, _ := ret[0].(iterator.Iterator[L1Validator]) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetActiveSubnetOnlyValidatorsIterator indicates an expected call of GetActiveSubnetOnlyValidatorsIterator. -func (mr *MockChainMockRecorder) GetActiveSubnetOnlyValidatorsIterator() *gomock.Call { +// GetActiveL1ValidatorsIterator indicates an expected call of GetActiveL1ValidatorsIterator. +func (mr *MockChainMockRecorder) GetActiveL1ValidatorsIterator() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveSubnetOnlyValidatorsIterator", reflect.TypeOf((*MockChain)(nil).GetActiveSubnetOnlyValidatorsIterator)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveL1ValidatorsIterator", reflect.TypeOf((*MockChain)(nil).GetActiveL1ValidatorsIterator)) } // GetCurrentDelegatorIterator mocks base method. @@ -323,6 +323,35 @@ func (mr *MockChainMockRecorder) GetFeeState() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeeState", reflect.TypeOf((*MockChain)(nil).GetFeeState)) } +// GetL1Validator mocks base method. +func (m *MockChain) GetL1Validator(validationID ids.ID) (L1Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1Validator", validationID) + ret0, _ := ret[0].(L1Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetL1Validator indicates an expected call of GetL1Validator. +func (mr *MockChainMockRecorder) GetL1Validator(validationID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1Validator", reflect.TypeOf((*MockChain)(nil).GetL1Validator), validationID) +} + +// GetL1ValidatorExcess mocks base method. +func (m *MockChain) GetL1ValidatorExcess() gas.Gas { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1ValidatorExcess") + ret0, _ := ret[0].(gas.Gas) + return ret0 +} + +// GetL1ValidatorExcess indicates an expected call of GetL1ValidatorExcess. +func (mr *MockChainMockRecorder) GetL1ValidatorExcess() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1ValidatorExcess", reflect.TypeOf((*MockChain)(nil).GetL1ValidatorExcess)) +} + // GetPendingDelegatorIterator mocks base method. func (m *MockChain) GetPendingDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error) { m.ctrl.T.Helper() @@ -368,63 +397,34 @@ func (mr *MockChainMockRecorder) GetPendingValidator(subnetID, nodeID any) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPendingValidator", reflect.TypeOf((*MockChain)(nil).GetPendingValidator), subnetID, nodeID) } -// GetSoVExcess mocks base method. -func (m *MockChain) GetSoVExcess() gas.Gas { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSoVExcess") - ret0, _ := ret[0].(gas.Gas) - return ret0 -} - -// GetSoVExcess indicates an expected call of GetSoVExcess. -func (mr *MockChainMockRecorder) GetSoVExcess() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSoVExcess", reflect.TypeOf((*MockChain)(nil).GetSoVExcess)) -} - -// GetSubnetConversion mocks base method. -func (m *MockChain) GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetConversion", subnetID) - ret0, _ := ret[0].(SubnetConversion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSubnetConversion indicates an expected call of GetSubnetConversion. -func (mr *MockChainMockRecorder) GetSubnetConversion(subnetID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetConversion", reflect.TypeOf((*MockChain)(nil).GetSubnetConversion), subnetID) -} - -// GetSubnetOnlyValidator mocks base method. -func (m *MockChain) GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { +// GetSubnetOwner mocks base method. +func (m *MockChain) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOnlyValidator", validationID) - ret0, _ := ret[0].(SubnetOnlyValidator) + ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) + ret0, _ := ret[0].(fx.Owner) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOnlyValidator indicates an expected call of GetSubnetOnlyValidator. -func (mr *MockChainMockRecorder) GetSubnetOnlyValidator(validationID any) *gomock.Call { +// GetSubnetOwner indicates an expected call of GetSubnetOwner. +func (mr *MockChainMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOnlyValidator", reflect.TypeOf((*MockChain)(nil).GetSubnetOnlyValidator), validationID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockChain)(nil).GetSubnetOwner), subnetID) } -// GetSubnetOwner mocks base method. -func (m *MockChain) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { +// GetSubnetToL1Conversion mocks base method. +func (m *MockChain) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) - ret0, _ := ret[0].(fx.Owner) + ret := m.ctrl.Call(m, "GetSubnetToL1Conversion", subnetID) + ret0, _ := ret[0].(SubnetToL1Conversion) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOwner indicates an expected call of GetSubnetOwner. -func (mr *MockChainMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { +// GetSubnetToL1Conversion indicates an expected call of GetSubnetToL1Conversion. +func (mr *MockChainMockRecorder) GetSubnetToL1Conversion(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockChain)(nil).GetSubnetOwner), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetToL1Conversion", reflect.TypeOf((*MockChain)(nil).GetSubnetToL1Conversion), subnetID) } // GetSubnetTransformation mocks base method. @@ -502,33 +502,33 @@ func (mr *MockChainMockRecorder) HasExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasExpiry", reflect.TypeOf((*MockChain)(nil).HasExpiry), arg0) } -// HasSubnetOnlyValidator mocks base method. -func (m *MockChain) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { +// HasL1Validator mocks base method. +func (m *MockChain) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HasSubnetOnlyValidator", subnetID, nodeID) + ret := m.ctrl.Call(m, "HasL1Validator", subnetID, nodeID) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } -// HasSubnetOnlyValidator indicates an expected call of HasSubnetOnlyValidator. -func (mr *MockChainMockRecorder) HasSubnetOnlyValidator(subnetID, nodeID any) *gomock.Call { +// HasL1Validator indicates an expected call of HasL1Validator. +func (mr *MockChainMockRecorder) HasL1Validator(subnetID, nodeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasSubnetOnlyValidator", reflect.TypeOf((*MockChain)(nil).HasSubnetOnlyValidator), subnetID, nodeID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasL1Validator", reflect.TypeOf((*MockChain)(nil).HasL1Validator), subnetID, nodeID) } -// NumActiveSubnetOnlyValidators mocks base method. -func (m *MockChain) NumActiveSubnetOnlyValidators() int { +// NumActiveL1Validators mocks base method. +func (m *MockChain) NumActiveL1Validators() int { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NumActiveSubnetOnlyValidators") + ret := m.ctrl.Call(m, "NumActiveL1Validators") ret0, _ := ret[0].(int) return ret0 } -// NumActiveSubnetOnlyValidators indicates an expected call of NumActiveSubnetOnlyValidators. -func (mr *MockChainMockRecorder) NumActiveSubnetOnlyValidators() *gomock.Call { +// NumActiveL1Validators indicates an expected call of NumActiveL1Validators. +func (mr *MockChainMockRecorder) NumActiveL1Validators() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveSubnetOnlyValidators", reflect.TypeOf((*MockChain)(nil).NumActiveSubnetOnlyValidators)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveL1Validators", reflect.TypeOf((*MockChain)(nil).NumActiveL1Validators)) } // PutCurrentDelegator mocks base method. @@ -569,6 +569,20 @@ func (mr *MockChainMockRecorder) PutExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutExpiry", reflect.TypeOf((*MockChain)(nil).PutExpiry), arg0) } +// PutL1Validator mocks base method. +func (m *MockChain) PutL1Validator(l1Validator L1Validator) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PutL1Validator", l1Validator) + ret0, _ := ret[0].(error) + return ret0 +} + +// PutL1Validator indicates an expected call of PutL1Validator. +func (mr *MockChainMockRecorder) PutL1Validator(l1Validator any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutL1Validator", reflect.TypeOf((*MockChain)(nil).PutL1Validator), l1Validator) +} + // PutPendingDelegator mocks base method. func (m *MockChain) PutPendingDelegator(staker *Staker) { m.ctrl.T.Helper() @@ -595,20 +609,6 @@ func (mr *MockChainMockRecorder) PutPendingValidator(staker any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutPendingValidator", reflect.TypeOf((*MockChain)(nil).PutPendingValidator), staker) } -// PutSubnetOnlyValidator mocks base method. -func (m *MockChain) PutSubnetOnlyValidator(sov SubnetOnlyValidator) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutSubnetOnlyValidator", sov) - ret0, _ := ret[0].(error) - return ret0 -} - -// PutSubnetOnlyValidator indicates an expected call of PutSubnetOnlyValidator. -func (mr *MockChainMockRecorder) PutSubnetOnlyValidator(sov any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutSubnetOnlyValidator", reflect.TypeOf((*MockChain)(nil).PutSubnetOnlyValidator), sov) -} - // SetAccruedFees mocks base method. func (m *MockChain) SetAccruedFees(f uint64) { m.ctrl.T.Helper() @@ -659,28 +659,16 @@ func (mr *MockChainMockRecorder) SetFeeState(f any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetFeeState", reflect.TypeOf((*MockChain)(nil).SetFeeState), f) } -// SetSoVExcess mocks base method. -func (m *MockChain) SetSoVExcess(e gas.Gas) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSoVExcess", e) -} - -// SetSoVExcess indicates an expected call of SetSoVExcess. -func (mr *MockChainMockRecorder) SetSoVExcess(e any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSoVExcess", reflect.TypeOf((*MockChain)(nil).SetSoVExcess), e) -} - -// SetSubnetConversion mocks base method. -func (m *MockChain) SetSubnetConversion(subnetID ids.ID, c SubnetConversion) { +// SetL1ValidatorExcess mocks base method. +func (m *MockChain) SetL1ValidatorExcess(e gas.Gas) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSubnetConversion", subnetID, c) + m.ctrl.Call(m, "SetL1ValidatorExcess", e) } -// SetSubnetConversion indicates an expected call of SetSubnetConversion. -func (mr *MockChainMockRecorder) SetSubnetConversion(subnetID, c any) *gomock.Call { +// SetL1ValidatorExcess indicates an expected call of SetL1ValidatorExcess. +func (mr *MockChainMockRecorder) SetL1ValidatorExcess(e any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetConversion", reflect.TypeOf((*MockChain)(nil).SetSubnetConversion), subnetID, c) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetL1ValidatorExcess", reflect.TypeOf((*MockChain)(nil).SetL1ValidatorExcess), e) } // SetSubnetOwner mocks base method. @@ -695,6 +683,18 @@ func (mr *MockChainMockRecorder) SetSubnetOwner(subnetID, owner any) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetOwner", reflect.TypeOf((*MockChain)(nil).SetSubnetOwner), subnetID, owner) } +// SetSubnetToL1Conversion mocks base method. +func (m *MockChain) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetSubnetToL1Conversion", subnetID, c) +} + +// SetSubnetToL1Conversion indicates an expected call of SetSubnetToL1Conversion. +func (mr *MockChainMockRecorder) SetSubnetToL1Conversion(subnetID, c any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetToL1Conversion", reflect.TypeOf((*MockChain)(nil).SetSubnetToL1Conversion), subnetID, c) +} + // SetTimestamp mocks base method. func (m *MockChain) SetTimestamp(tm time.Time) { m.ctrl.T.Helper() @@ -707,17 +707,17 @@ func (mr *MockChainMockRecorder) SetTimestamp(tm any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTimestamp", reflect.TypeOf((*MockChain)(nil).SetTimestamp), tm) } -// WeightOfSubnetOnlyValidators mocks base method. -func (m *MockChain) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { +// WeightOfL1Validators mocks base method. +func (m *MockChain) WeightOfL1Validators(subnetID ids.ID) (uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WeightOfSubnetOnlyValidators", subnetID) + ret := m.ctrl.Call(m, "WeightOfL1Validators", subnetID) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } -// WeightOfSubnetOnlyValidators indicates an expected call of WeightOfSubnetOnlyValidators. -func (mr *MockChainMockRecorder) WeightOfSubnetOnlyValidators(subnetID any) *gomock.Call { +// WeightOfL1Validators indicates an expected call of WeightOfL1Validators. +func (mr *MockChainMockRecorder) WeightOfL1Validators(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfSubnetOnlyValidators", reflect.TypeOf((*MockChain)(nil).WeightOfSubnetOnlyValidators), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfL1Validators", reflect.TypeOf((*MockChain)(nil).WeightOfL1Validators), subnetID) } diff --git a/vms/platformvm/state/mock_diff.go b/vms/platformvm/state/mock_diff.go index 30f17a781227..94481109ac59 100644 --- a/vms/platformvm/state/mock_diff.go +++ b/vms/platformvm/state/mock_diff.go @@ -218,19 +218,19 @@ func (mr *MockDiffMockRecorder) GetAccruedFees() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccruedFees", reflect.TypeOf((*MockDiff)(nil).GetAccruedFees)) } -// GetActiveSubnetOnlyValidatorsIterator mocks base method. -func (m *MockDiff) GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) { +// GetActiveL1ValidatorsIterator mocks base method. +func (m *MockDiff) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetActiveSubnetOnlyValidatorsIterator") - ret0, _ := ret[0].(iterator.Iterator[SubnetOnlyValidator]) + ret := m.ctrl.Call(m, "GetActiveL1ValidatorsIterator") + ret0, _ := ret[0].(iterator.Iterator[L1Validator]) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetActiveSubnetOnlyValidatorsIterator indicates an expected call of GetActiveSubnetOnlyValidatorsIterator. -func (mr *MockDiffMockRecorder) GetActiveSubnetOnlyValidatorsIterator() *gomock.Call { +// GetActiveL1ValidatorsIterator indicates an expected call of GetActiveL1ValidatorsIterator. +func (mr *MockDiffMockRecorder) GetActiveL1ValidatorsIterator() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveSubnetOnlyValidatorsIterator", reflect.TypeOf((*MockDiff)(nil).GetActiveSubnetOnlyValidatorsIterator)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveL1ValidatorsIterator", reflect.TypeOf((*MockDiff)(nil).GetActiveL1ValidatorsIterator)) } // GetCurrentDelegatorIterator mocks base method. @@ -337,6 +337,35 @@ func (mr *MockDiffMockRecorder) GetFeeState() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeeState", reflect.TypeOf((*MockDiff)(nil).GetFeeState)) } +// GetL1Validator mocks base method. +func (m *MockDiff) GetL1Validator(validationID ids.ID) (L1Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1Validator", validationID) + ret0, _ := ret[0].(L1Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetL1Validator indicates an expected call of GetL1Validator. +func (mr *MockDiffMockRecorder) GetL1Validator(validationID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1Validator", reflect.TypeOf((*MockDiff)(nil).GetL1Validator), validationID) +} + +// GetL1ValidatorExcess mocks base method. +func (m *MockDiff) GetL1ValidatorExcess() gas.Gas { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1ValidatorExcess") + ret0, _ := ret[0].(gas.Gas) + return ret0 +} + +// GetL1ValidatorExcess indicates an expected call of GetL1ValidatorExcess. +func (mr *MockDiffMockRecorder) GetL1ValidatorExcess() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1ValidatorExcess", reflect.TypeOf((*MockDiff)(nil).GetL1ValidatorExcess)) +} + // GetPendingDelegatorIterator mocks base method. func (m *MockDiff) GetPendingDelegatorIterator(subnetID ids.ID, nodeID ids.NodeID) (iterator.Iterator[*Staker], error) { m.ctrl.T.Helper() @@ -382,63 +411,34 @@ func (mr *MockDiffMockRecorder) GetPendingValidator(subnetID, nodeID any) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPendingValidator", reflect.TypeOf((*MockDiff)(nil).GetPendingValidator), subnetID, nodeID) } -// GetSoVExcess mocks base method. -func (m *MockDiff) GetSoVExcess() gas.Gas { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSoVExcess") - ret0, _ := ret[0].(gas.Gas) - return ret0 -} - -// GetSoVExcess indicates an expected call of GetSoVExcess. -func (mr *MockDiffMockRecorder) GetSoVExcess() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSoVExcess", reflect.TypeOf((*MockDiff)(nil).GetSoVExcess)) -} - -// GetSubnetConversion mocks base method. -func (m *MockDiff) GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetConversion", subnetID) - ret0, _ := ret[0].(SubnetConversion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSubnetConversion indicates an expected call of GetSubnetConversion. -func (mr *MockDiffMockRecorder) GetSubnetConversion(subnetID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetConversion", reflect.TypeOf((*MockDiff)(nil).GetSubnetConversion), subnetID) -} - -// GetSubnetOnlyValidator mocks base method. -func (m *MockDiff) GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { +// GetSubnetOwner mocks base method. +func (m *MockDiff) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOnlyValidator", validationID) - ret0, _ := ret[0].(SubnetOnlyValidator) + ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) + ret0, _ := ret[0].(fx.Owner) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOnlyValidator indicates an expected call of GetSubnetOnlyValidator. -func (mr *MockDiffMockRecorder) GetSubnetOnlyValidator(validationID any) *gomock.Call { +// GetSubnetOwner indicates an expected call of GetSubnetOwner. +func (mr *MockDiffMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOnlyValidator", reflect.TypeOf((*MockDiff)(nil).GetSubnetOnlyValidator), validationID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockDiff)(nil).GetSubnetOwner), subnetID) } -// GetSubnetOwner mocks base method. -func (m *MockDiff) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { +// GetSubnetToL1Conversion mocks base method. +func (m *MockDiff) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) - ret0, _ := ret[0].(fx.Owner) + ret := m.ctrl.Call(m, "GetSubnetToL1Conversion", subnetID) + ret0, _ := ret[0].(SubnetToL1Conversion) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOwner indicates an expected call of GetSubnetOwner. -func (mr *MockDiffMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { +// GetSubnetToL1Conversion indicates an expected call of GetSubnetToL1Conversion. +func (mr *MockDiffMockRecorder) GetSubnetToL1Conversion(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockDiff)(nil).GetSubnetOwner), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetToL1Conversion", reflect.TypeOf((*MockDiff)(nil).GetSubnetToL1Conversion), subnetID) } // GetSubnetTransformation mocks base method. @@ -516,33 +516,33 @@ func (mr *MockDiffMockRecorder) HasExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasExpiry", reflect.TypeOf((*MockDiff)(nil).HasExpiry), arg0) } -// HasSubnetOnlyValidator mocks base method. -func (m *MockDiff) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { +// HasL1Validator mocks base method. +func (m *MockDiff) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HasSubnetOnlyValidator", subnetID, nodeID) + ret := m.ctrl.Call(m, "HasL1Validator", subnetID, nodeID) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } -// HasSubnetOnlyValidator indicates an expected call of HasSubnetOnlyValidator. -func (mr *MockDiffMockRecorder) HasSubnetOnlyValidator(subnetID, nodeID any) *gomock.Call { +// HasL1Validator indicates an expected call of HasL1Validator. +func (mr *MockDiffMockRecorder) HasL1Validator(subnetID, nodeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasSubnetOnlyValidator", reflect.TypeOf((*MockDiff)(nil).HasSubnetOnlyValidator), subnetID, nodeID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasL1Validator", reflect.TypeOf((*MockDiff)(nil).HasL1Validator), subnetID, nodeID) } -// NumActiveSubnetOnlyValidators mocks base method. -func (m *MockDiff) NumActiveSubnetOnlyValidators() int { +// NumActiveL1Validators mocks base method. +func (m *MockDiff) NumActiveL1Validators() int { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NumActiveSubnetOnlyValidators") + ret := m.ctrl.Call(m, "NumActiveL1Validators") ret0, _ := ret[0].(int) return ret0 } -// NumActiveSubnetOnlyValidators indicates an expected call of NumActiveSubnetOnlyValidators. -func (mr *MockDiffMockRecorder) NumActiveSubnetOnlyValidators() *gomock.Call { +// NumActiveL1Validators indicates an expected call of NumActiveL1Validators. +func (mr *MockDiffMockRecorder) NumActiveL1Validators() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveSubnetOnlyValidators", reflect.TypeOf((*MockDiff)(nil).NumActiveSubnetOnlyValidators)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveL1Validators", reflect.TypeOf((*MockDiff)(nil).NumActiveL1Validators)) } // PutCurrentDelegator mocks base method. @@ -583,6 +583,20 @@ func (mr *MockDiffMockRecorder) PutExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutExpiry", reflect.TypeOf((*MockDiff)(nil).PutExpiry), arg0) } +// PutL1Validator mocks base method. +func (m *MockDiff) PutL1Validator(l1Validator L1Validator) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PutL1Validator", l1Validator) + ret0, _ := ret[0].(error) + return ret0 +} + +// PutL1Validator indicates an expected call of PutL1Validator. +func (mr *MockDiffMockRecorder) PutL1Validator(l1Validator any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutL1Validator", reflect.TypeOf((*MockDiff)(nil).PutL1Validator), l1Validator) +} + // PutPendingDelegator mocks base method. func (m *MockDiff) PutPendingDelegator(staker *Staker) { m.ctrl.T.Helper() @@ -609,20 +623,6 @@ func (mr *MockDiffMockRecorder) PutPendingValidator(staker any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutPendingValidator", reflect.TypeOf((*MockDiff)(nil).PutPendingValidator), staker) } -// PutSubnetOnlyValidator mocks base method. -func (m *MockDiff) PutSubnetOnlyValidator(sov SubnetOnlyValidator) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutSubnetOnlyValidator", sov) - ret0, _ := ret[0].(error) - return ret0 -} - -// PutSubnetOnlyValidator indicates an expected call of PutSubnetOnlyValidator. -func (mr *MockDiffMockRecorder) PutSubnetOnlyValidator(sov any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutSubnetOnlyValidator", reflect.TypeOf((*MockDiff)(nil).PutSubnetOnlyValidator), sov) -} - // SetAccruedFees mocks base method. func (m *MockDiff) SetAccruedFees(f uint64) { m.ctrl.T.Helper() @@ -673,28 +673,16 @@ func (mr *MockDiffMockRecorder) SetFeeState(f any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetFeeState", reflect.TypeOf((*MockDiff)(nil).SetFeeState), f) } -// SetSoVExcess mocks base method. -func (m *MockDiff) SetSoVExcess(e gas.Gas) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSoVExcess", e) -} - -// SetSoVExcess indicates an expected call of SetSoVExcess. -func (mr *MockDiffMockRecorder) SetSoVExcess(e any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSoVExcess", reflect.TypeOf((*MockDiff)(nil).SetSoVExcess), e) -} - -// SetSubnetConversion mocks base method. -func (m *MockDiff) SetSubnetConversion(subnetID ids.ID, c SubnetConversion) { +// SetL1ValidatorExcess mocks base method. +func (m *MockDiff) SetL1ValidatorExcess(e gas.Gas) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSubnetConversion", subnetID, c) + m.ctrl.Call(m, "SetL1ValidatorExcess", e) } -// SetSubnetConversion indicates an expected call of SetSubnetConversion. -func (mr *MockDiffMockRecorder) SetSubnetConversion(subnetID, c any) *gomock.Call { +// SetL1ValidatorExcess indicates an expected call of SetL1ValidatorExcess. +func (mr *MockDiffMockRecorder) SetL1ValidatorExcess(e any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetConversion", reflect.TypeOf((*MockDiff)(nil).SetSubnetConversion), subnetID, c) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetL1ValidatorExcess", reflect.TypeOf((*MockDiff)(nil).SetL1ValidatorExcess), e) } // SetSubnetOwner mocks base method. @@ -709,6 +697,18 @@ func (mr *MockDiffMockRecorder) SetSubnetOwner(subnetID, owner any) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetOwner", reflect.TypeOf((*MockDiff)(nil).SetSubnetOwner), subnetID, owner) } +// SetSubnetToL1Conversion mocks base method. +func (m *MockDiff) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetSubnetToL1Conversion", subnetID, c) +} + +// SetSubnetToL1Conversion indicates an expected call of SetSubnetToL1Conversion. +func (mr *MockDiffMockRecorder) SetSubnetToL1Conversion(subnetID, c any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetToL1Conversion", reflect.TypeOf((*MockDiff)(nil).SetSubnetToL1Conversion), subnetID, c) +} + // SetTimestamp mocks base method. func (m *MockDiff) SetTimestamp(tm time.Time) { m.ctrl.T.Helper() @@ -721,17 +721,17 @@ func (mr *MockDiffMockRecorder) SetTimestamp(tm any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTimestamp", reflect.TypeOf((*MockDiff)(nil).SetTimestamp), tm) } -// WeightOfSubnetOnlyValidators mocks base method. -func (m *MockDiff) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { +// WeightOfL1Validators mocks base method. +func (m *MockDiff) WeightOfL1Validators(subnetID ids.ID) (uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WeightOfSubnetOnlyValidators", subnetID) + ret := m.ctrl.Call(m, "WeightOfL1Validators", subnetID) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } -// WeightOfSubnetOnlyValidators indicates an expected call of WeightOfSubnetOnlyValidators. -func (mr *MockDiffMockRecorder) WeightOfSubnetOnlyValidators(subnetID any) *gomock.Call { +// WeightOfL1Validators indicates an expected call of WeightOfL1Validators. +func (mr *MockDiffMockRecorder) WeightOfL1Validators(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfSubnetOnlyValidators", reflect.TypeOf((*MockDiff)(nil).WeightOfSubnetOnlyValidators), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfL1Validators", reflect.TypeOf((*MockDiff)(nil).WeightOfL1Validators), subnetID) } diff --git a/vms/platformvm/state/mock_state.go b/vms/platformvm/state/mock_state.go index b7fa1de35f8e..184b2c9563f3 100644 --- a/vms/platformvm/state/mock_state.go +++ b/vms/platformvm/state/mock_state.go @@ -319,19 +319,19 @@ func (mr *MockStateMockRecorder) GetAccruedFees() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccruedFees", reflect.TypeOf((*MockState)(nil).GetAccruedFees)) } -// GetActiveSubnetOnlyValidatorsIterator mocks base method. -func (m *MockState) GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) { +// GetActiveL1ValidatorsIterator mocks base method. +func (m *MockState) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetActiveSubnetOnlyValidatorsIterator") - ret0, _ := ret[0].(iterator.Iterator[SubnetOnlyValidator]) + ret := m.ctrl.Call(m, "GetActiveL1ValidatorsIterator") + ret0, _ := ret[0].(iterator.Iterator[L1Validator]) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetActiveSubnetOnlyValidatorsIterator indicates an expected call of GetActiveSubnetOnlyValidatorsIterator. -func (mr *MockStateMockRecorder) GetActiveSubnetOnlyValidatorsIterator() *gomock.Call { +// GetActiveL1ValidatorsIterator indicates an expected call of GetActiveL1ValidatorsIterator. +func (mr *MockStateMockRecorder) GetActiveL1ValidatorsIterator() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveSubnetOnlyValidatorsIterator", reflect.TypeOf((*MockState)(nil).GetActiveSubnetOnlyValidatorsIterator)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveL1ValidatorsIterator", reflect.TypeOf((*MockState)(nil).GetActiveL1ValidatorsIterator)) } // GetBlockIDAtHeight mocks base method. @@ -499,6 +499,35 @@ func (mr *MockStateMockRecorder) GetFeeState() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeeState", reflect.TypeOf((*MockState)(nil).GetFeeState)) } +// GetL1Validator mocks base method. +func (m *MockState) GetL1Validator(validationID ids.ID) (L1Validator, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1Validator", validationID) + ret0, _ := ret[0].(L1Validator) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetL1Validator indicates an expected call of GetL1Validator. +func (mr *MockStateMockRecorder) GetL1Validator(validationID any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1Validator", reflect.TypeOf((*MockState)(nil).GetL1Validator), validationID) +} + +// GetL1ValidatorExcess mocks base method. +func (m *MockState) GetL1ValidatorExcess() gas.Gas { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetL1ValidatorExcess") + ret0, _ := ret[0].(gas.Gas) + return ret0 +} + +// GetL1ValidatorExcess indicates an expected call of GetL1ValidatorExcess. +func (mr *MockStateMockRecorder) GetL1ValidatorExcess() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetL1ValidatorExcess", reflect.TypeOf((*MockState)(nil).GetL1ValidatorExcess)) +} + // GetLastAccepted mocks base method. func (m *MockState) GetLastAccepted() ids.ID { m.ctrl.T.Helper() @@ -573,20 +602,6 @@ func (mr *MockStateMockRecorder) GetRewardUTXOs(txID any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRewardUTXOs", reflect.TypeOf((*MockState)(nil).GetRewardUTXOs), txID) } -// GetSoVExcess mocks base method. -func (m *MockState) GetSoVExcess() gas.Gas { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSoVExcess") - ret0, _ := ret[0].(gas.Gas) - return ret0 -} - -// GetSoVExcess indicates an expected call of GetSoVExcess. -func (mr *MockStateMockRecorder) GetSoVExcess() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSoVExcess", reflect.TypeOf((*MockState)(nil).GetSoVExcess)) -} - // GetStartTime mocks base method. func (m *MockState) GetStartTime(nodeID ids.NodeID) (time.Time, error) { m.ctrl.T.Helper() @@ -617,21 +632,6 @@ func (mr *MockStateMockRecorder) GetStatelessBlock(blockID any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStatelessBlock", reflect.TypeOf((*MockState)(nil).GetStatelessBlock), blockID) } -// GetSubnetConversion mocks base method. -func (m *MockState) GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetConversion", subnetID) - ret0, _ := ret[0].(SubnetConversion) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSubnetConversion indicates an expected call of GetSubnetConversion. -func (mr *MockStateMockRecorder) GetSubnetConversion(subnetID any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetConversion", reflect.TypeOf((*MockState)(nil).GetSubnetConversion), subnetID) -} - // GetSubnetIDs mocks base method. func (m *MockState) GetSubnetIDs() ([]ids.ID, error) { m.ctrl.T.Helper() @@ -647,34 +647,34 @@ func (mr *MockStateMockRecorder) GetSubnetIDs() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetIDs", reflect.TypeOf((*MockState)(nil).GetSubnetIDs)) } -// GetSubnetOnlyValidator mocks base method. -func (m *MockState) GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { +// GetSubnetOwner mocks base method. +func (m *MockState) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOnlyValidator", validationID) - ret0, _ := ret[0].(SubnetOnlyValidator) + ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) + ret0, _ := ret[0].(fx.Owner) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOnlyValidator indicates an expected call of GetSubnetOnlyValidator. -func (mr *MockStateMockRecorder) GetSubnetOnlyValidator(validationID any) *gomock.Call { +// GetSubnetOwner indicates an expected call of GetSubnetOwner. +func (mr *MockStateMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOnlyValidator", reflect.TypeOf((*MockState)(nil).GetSubnetOnlyValidator), validationID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockState)(nil).GetSubnetOwner), subnetID) } -// GetSubnetOwner mocks base method. -func (m *MockState) GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) { +// GetSubnetToL1Conversion mocks base method. +func (m *MockState) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSubnetOwner", subnetID) - ret0, _ := ret[0].(fx.Owner) + ret := m.ctrl.Call(m, "GetSubnetToL1Conversion", subnetID) + ret0, _ := ret[0].(SubnetToL1Conversion) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetSubnetOwner indicates an expected call of GetSubnetOwner. -func (mr *MockStateMockRecorder) GetSubnetOwner(subnetID any) *gomock.Call { +// GetSubnetToL1Conversion indicates an expected call of GetSubnetToL1Conversion. +func (mr *MockStateMockRecorder) GetSubnetToL1Conversion(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetOwner", reflect.TypeOf((*MockState)(nil).GetSubnetOwner), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSubnetToL1Conversion", reflect.TypeOf((*MockState)(nil).GetSubnetToL1Conversion), subnetID) } // GetSubnetTransformation mocks base method. @@ -768,33 +768,33 @@ func (mr *MockStateMockRecorder) HasExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasExpiry", reflect.TypeOf((*MockState)(nil).HasExpiry), arg0) } -// HasSubnetOnlyValidator mocks base method. -func (m *MockState) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { +// HasL1Validator mocks base method. +func (m *MockState) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HasSubnetOnlyValidator", subnetID, nodeID) + ret := m.ctrl.Call(m, "HasL1Validator", subnetID, nodeID) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } -// HasSubnetOnlyValidator indicates an expected call of HasSubnetOnlyValidator. -func (mr *MockStateMockRecorder) HasSubnetOnlyValidator(subnetID, nodeID any) *gomock.Call { +// HasL1Validator indicates an expected call of HasL1Validator. +func (mr *MockStateMockRecorder) HasL1Validator(subnetID, nodeID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasSubnetOnlyValidator", reflect.TypeOf((*MockState)(nil).HasSubnetOnlyValidator), subnetID, nodeID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasL1Validator", reflect.TypeOf((*MockState)(nil).HasL1Validator), subnetID, nodeID) } -// NumActiveSubnetOnlyValidators mocks base method. -func (m *MockState) NumActiveSubnetOnlyValidators() int { +// NumActiveL1Validators mocks base method. +func (m *MockState) NumActiveL1Validators() int { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NumActiveSubnetOnlyValidators") + ret := m.ctrl.Call(m, "NumActiveL1Validators") ret0, _ := ret[0].(int) return ret0 } -// NumActiveSubnetOnlyValidators indicates an expected call of NumActiveSubnetOnlyValidators. -func (mr *MockStateMockRecorder) NumActiveSubnetOnlyValidators() *gomock.Call { +// NumActiveL1Validators indicates an expected call of NumActiveL1Validators. +func (mr *MockStateMockRecorder) NumActiveL1Validators() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveSubnetOnlyValidators", reflect.TypeOf((*MockState)(nil).NumActiveSubnetOnlyValidators)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NumActiveL1Validators", reflect.TypeOf((*MockState)(nil).NumActiveL1Validators)) } // PutCurrentDelegator mocks base method. @@ -835,6 +835,20 @@ func (mr *MockStateMockRecorder) PutExpiry(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutExpiry", reflect.TypeOf((*MockState)(nil).PutExpiry), arg0) } +// PutL1Validator mocks base method. +func (m *MockState) PutL1Validator(l1Validator L1Validator) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PutL1Validator", l1Validator) + ret0, _ := ret[0].(error) + return ret0 +} + +// PutL1Validator indicates an expected call of PutL1Validator. +func (mr *MockStateMockRecorder) PutL1Validator(l1Validator any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutL1Validator", reflect.TypeOf((*MockState)(nil).PutL1Validator), l1Validator) +} + // PutPendingDelegator mocks base method. func (m *MockState) PutPendingDelegator(staker *Staker) { m.ctrl.T.Helper() @@ -861,20 +875,6 @@ func (mr *MockStateMockRecorder) PutPendingValidator(staker any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutPendingValidator", reflect.TypeOf((*MockState)(nil).PutPendingValidator), staker) } -// PutSubnetOnlyValidator mocks base method. -func (m *MockState) PutSubnetOnlyValidator(sov SubnetOnlyValidator) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutSubnetOnlyValidator", sov) - ret0, _ := ret[0].(error) - return ret0 -} - -// PutSubnetOnlyValidator indicates an expected call of PutSubnetOnlyValidator. -func (mr *MockStateMockRecorder) PutSubnetOnlyValidator(sov any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutSubnetOnlyValidator", reflect.TypeOf((*MockState)(nil).PutSubnetOnlyValidator), sov) -} - // ReindexBlocks mocks base method. func (m *MockState) ReindexBlocks(lock sync.Locker, log logging.Logger) error { m.ctrl.T.Helper() @@ -951,40 +951,28 @@ func (mr *MockStateMockRecorder) SetHeight(height any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHeight", reflect.TypeOf((*MockState)(nil).SetHeight), height) } -// SetLastAccepted mocks base method. -func (m *MockState) SetLastAccepted(blkID ids.ID) { +// SetL1ValidatorExcess mocks base method. +func (m *MockState) SetL1ValidatorExcess(e gas.Gas) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SetLastAccepted", blkID) + m.ctrl.Call(m, "SetL1ValidatorExcess", e) } -// SetLastAccepted indicates an expected call of SetLastAccepted. -func (mr *MockStateMockRecorder) SetLastAccepted(blkID any) *gomock.Call { +// SetL1ValidatorExcess indicates an expected call of SetL1ValidatorExcess. +func (mr *MockStateMockRecorder) SetL1ValidatorExcess(e any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLastAccepted", reflect.TypeOf((*MockState)(nil).SetLastAccepted), blkID) -} - -// SetSoVExcess mocks base method. -func (m *MockState) SetSoVExcess(e gas.Gas) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSoVExcess", e) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetL1ValidatorExcess", reflect.TypeOf((*MockState)(nil).SetL1ValidatorExcess), e) } -// SetSoVExcess indicates an expected call of SetSoVExcess. -func (mr *MockStateMockRecorder) SetSoVExcess(e any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSoVExcess", reflect.TypeOf((*MockState)(nil).SetSoVExcess), e) -} - -// SetSubnetConversion mocks base method. -func (m *MockState) SetSubnetConversion(subnetID ids.ID, c SubnetConversion) { +// SetLastAccepted mocks base method. +func (m *MockState) SetLastAccepted(blkID ids.ID) { m.ctrl.T.Helper() - m.ctrl.Call(m, "SetSubnetConversion", subnetID, c) + m.ctrl.Call(m, "SetLastAccepted", blkID) } -// SetSubnetConversion indicates an expected call of SetSubnetConversion. -func (mr *MockStateMockRecorder) SetSubnetConversion(subnetID, c any) *gomock.Call { +// SetLastAccepted indicates an expected call of SetLastAccepted. +func (mr *MockStateMockRecorder) SetLastAccepted(blkID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetConversion", reflect.TypeOf((*MockState)(nil).SetSubnetConversion), subnetID, c) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLastAccepted", reflect.TypeOf((*MockState)(nil).SetLastAccepted), blkID) } // SetSubnetOwner mocks base method. @@ -999,6 +987,18 @@ func (mr *MockStateMockRecorder) SetSubnetOwner(subnetID, owner any) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetOwner", reflect.TypeOf((*MockState)(nil).SetSubnetOwner), subnetID, owner) } +// SetSubnetToL1Conversion mocks base method. +func (m *MockState) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetSubnetToL1Conversion", subnetID, c) +} + +// SetSubnetToL1Conversion indicates an expected call of SetSubnetToL1Conversion. +func (mr *MockStateMockRecorder) SetSubnetToL1Conversion(subnetID, c any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSubnetToL1Conversion", reflect.TypeOf((*MockState)(nil).SetSubnetToL1Conversion), subnetID, c) +} + // SetTimestamp mocks base method. func (m *MockState) SetTimestamp(tm time.Time) { m.ctrl.T.Helper() @@ -1040,17 +1040,17 @@ func (mr *MockStateMockRecorder) UTXOIDs(addr, previous, limit any) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UTXOIDs", reflect.TypeOf((*MockState)(nil).UTXOIDs), addr, previous, limit) } -// WeightOfSubnetOnlyValidators mocks base method. -func (m *MockState) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { +// WeightOfL1Validators mocks base method. +func (m *MockState) WeightOfL1Validators(subnetID ids.ID) (uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WeightOfSubnetOnlyValidators", subnetID) + ret := m.ctrl.Call(m, "WeightOfL1Validators", subnetID) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } -// WeightOfSubnetOnlyValidators indicates an expected call of WeightOfSubnetOnlyValidators. -func (mr *MockStateMockRecorder) WeightOfSubnetOnlyValidators(subnetID any) *gomock.Call { +// WeightOfL1Validators indicates an expected call of WeightOfL1Validators. +func (mr *MockStateMockRecorder) WeightOfL1Validators(subnetID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfSubnetOnlyValidators", reflect.TypeOf((*MockState)(nil).WeightOfSubnetOnlyValidators), subnetID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WeightOfL1Validators", reflect.TypeOf((*MockState)(nil).WeightOfL1Validators), subnetID) } diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index 37df8fc0444f..95d973b2e4ed 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -82,37 +82,37 @@ var ( UTXOPrefix = []byte("utxo") SubnetPrefix = []byte("subnet") SubnetOwnerPrefix = []byte("subnetOwner") - SubnetConversionPrefix = []byte("subnetConversion") + SubnetToL1ConversionPrefix = []byte("subnetToL1Conversion") TransformedSubnetPrefix = []byte("transformedSubnet") SupplyPrefix = []byte("supply") ChainPrefix = []byte("chain") ExpiryReplayProtectionPrefix = []byte("expiryReplayProtection") - SubnetOnlyPrefix = []byte("subnetOnly") + L1Prefix = []byte("l1") WeightsPrefix = []byte("weights") SubnetIDNodeIDPrefix = []byte("subnetIDNodeID") ActivePrefix = []byte("active") InactivePrefix = []byte("inactive") SingletonPrefix = []byte("singleton") - EtnaHeightKey = []byte("etna height") - TimestampKey = []byte("timestamp") - FeeStateKey = []byte("fee state") - SoVExcessKey = []byte("sov excess") - AccruedFeesKey = []byte("accrued fees") - CurrentSupplyKey = []byte("current supply") - LastAcceptedKey = []byte("last accepted") - HeightsIndexedKey = []byte("heights indexed") - InitializedKey = []byte("initialized") - BlocksReindexedKey = []byte("blocks reindexed") - - emptySoVCache = &cache.Empty[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{} + EtnaHeightKey = []byte("etna height") + TimestampKey = []byte("timestamp") + FeeStateKey = []byte("fee state") + L1ValidatorExcessKey = []byte("l1Validator excess") + AccruedFeesKey = []byte("accrued fees") + CurrentSupplyKey = []byte("current supply") + LastAcceptedKey = []byte("last accepted") + HeightsIndexedKey = []byte("heights indexed") + InitializedKey = []byte("initialized") + BlocksReindexedKey = []byte("blocks reindexed") + + emptyL1ValidatorCache = &cache.Empty[ids.ID, maybe.Maybe[L1Validator]]{} ) // Chain collects all methods to manage the state of the chain for block // execution. type Chain interface { Expiry - SubnetOnlyValidators + L1Validators Stakers avax.UTXOAdder avax.UTXOGetter @@ -124,8 +124,8 @@ type Chain interface { GetFeeState() gas.State SetFeeState(f gas.State) - GetSoVExcess() gas.Gas - SetSoVExcess(e gas.Gas) + GetL1ValidatorExcess() gas.Gas + SetL1ValidatorExcess(e gas.Gas) GetAccruedFees() uint64 SetAccruedFees(f uint64) @@ -140,8 +140,8 @@ type Chain interface { GetSubnetOwner(subnetID ids.ID) (fx.Owner, error) SetSubnetOwner(subnetID ids.ID, owner fx.Owner) - GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) - SetSubnetConversion(subnetID ids.ID, c SubnetConversion) + GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) + SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) GetSubnetTransformation(subnetID ids.ID) (*txs.Tx, error) AddSubnetTransformation(transformSubnetTx *txs.Tx) @@ -278,15 +278,15 @@ type stateBlk struct { * | | '-. subnetDelegator * | | '-. list * | | '-- txID -> nil - * | |-. subnetOnly + * | |-. l1 * | | |-. weights * | | | '-- subnetID -> weight * | | |-. subnetIDNodeID * | | | '-- subnetID+nodeID -> validationID * | | |-. active - * | | | '-- validationID -> subnetOnlyValidator + * | | | '-- validationID -> l1Validator * | | '-. inactive - * | | '-- validationID -> subnetOnlyValidator + * | | '-- validationID -> l1Validator * | |-. weight diffs * | | '-- subnet+height+nodeID -> weightChange * | '-. pub key diffs @@ -308,7 +308,7 @@ type stateBlk struct { * | '-- txID -> nil * |-. subnetOwners * | '-- subnetID -> owner - * |-. subnetConversions + * |-. subnetToL1Conversions * | '-- subnetID -> conversionID + chainID + addr * |-. chains * | '-. subnetID @@ -322,7 +322,7 @@ type stateBlk struct { * |-- etnaHeightKey -> height * |-- timestampKey -> timestamp * |-- feeStateKey -> feeState - * |-- sovExcessKey -> sovExcess + * |-- l1ValidatorExcessKey -> l1ValidatorExcess * |-- accruedFeesKey -> accruedFees * |-- currentSupplyKey -> currentSupply * |-- lastAcceptedKey -> lastAccepted @@ -343,16 +343,16 @@ type state struct { expiryDiff *expiryDiff expiryDB database.Database - activeSOVs *activeSubnetOnlyValidators - sovDiff *subnetOnlyValidatorsDiff - subnetOnlyValidatorsDB database.Database - weightsCache cache.Cacher[ids.ID, uint64] // subnetID -> total SoV weight - weightsDB database.Database - subnetIDNodeIDCache cache.Cacher[subnetIDNodeID, bool] // subnetID+nodeID -> is validator - subnetIDNodeIDDB database.Database - activeDB database.Database - inactiveCache cache.Cacher[ids.ID, maybe.Maybe[SubnetOnlyValidator]] // validationID -> SubnetOnlyValidator - inactiveDB database.Database + activeL1Validators *activeL1Validators + l1ValidatorsDiff *l1ValidatorsDiff + l1ValidatorsDB database.Database + weightsCache cache.Cacher[ids.ID, uint64] // subnetID -> total L1 validator weight + weightsDB database.Database + subnetIDNodeIDCache cache.Cacher[subnetIDNodeID, bool] // subnetID+nodeID -> is validator + subnetIDNodeIDDB database.Database + activeDB database.Database + inactiveCache cache.Cacher[ids.ID, maybe.Maybe[L1Validator]] // validationID -> L1Validator + inactiveDB database.Database currentStakers *baseStakers pendingStakers *baseStakers @@ -411,9 +411,9 @@ type state struct { subnetOwnerCache cache.Cacher[ids.ID, fxOwnerAndSize] // cache of subnetID -> owner; if the entry is nil, it is not in the database subnetOwnerDB database.Database - subnetConversions map[ids.ID]SubnetConversion // map of subnetID -> conversion of the subnet - subnetConversionCache cache.Cacher[ids.ID, SubnetConversion] // cache of subnetID -> conversion - subnetConversionDB database.Database + subnetToL1Conversions map[ids.ID]SubnetToL1Conversion // map of subnetID -> conversion of the subnet + subnetToL1ConversionCache cache.Cacher[ids.ID, SubnetToL1Conversion] // cache of subnetID -> conversion + subnetToL1ConversionDB database.Database transformedSubnets map[ids.ID]*txs.Tx // map of subnetID -> transformSubnetTx transformedSubnetCache cache.Cacher[ids.ID, *txs.Tx] // cache of subnetID -> transformSubnetTx; if the entry is nil, it is not in the database @@ -429,11 +429,11 @@ type state struct { chainDB database.Database // The persisted fields represent the current database value - timestamp, persistedTimestamp time.Time - feeState, persistedFeeState gas.State - sovExcess, persistedSOVExcess gas.Gas - accruedFees, persistedAccruedFees uint64 - currentSupply, persistedCurrentSupply uint64 + timestamp, persistedTimestamp time.Time + feeState, persistedFeeState gas.State + l1ValidatorExcess, persistedL1ValidatorExcess gas.Gas + accruedFees, persistedAccruedFees uint64 + currentSupply, persistedCurrentSupply uint64 // [lastAccepted] is the most recently accepted block. lastAccepted, persistedLastAccepted ids.ID // TODO: Remove indexedHeights once v1.11.3 has been released. @@ -495,7 +495,7 @@ type fxOwnerAndSize struct { size int } -type SubnetConversion struct { +type SubnetToL1Conversion struct { ConversionID ids.ID `serialize:"true"` ChainID ids.ID `serialize:"true"` Addr []byte `serialize:"true"` @@ -567,13 +567,13 @@ func New( pendingSubnetValidatorBaseDB := prefixdb.New(SubnetValidatorPrefix, pendingValidatorsDB) pendingSubnetDelegatorBaseDB := prefixdb.New(SubnetDelegatorPrefix, pendingValidatorsDB) - subnetOnlyValidatorsDB := prefixdb.New(SubnetOnlyPrefix, validatorsDB) + l1ValidatorsDB := prefixdb.New(L1Prefix, validatorsDB) validatorWeightDiffsDB := prefixdb.New(ValidatorWeightDiffsPrefix, validatorsDB) validatorPublicKeyDiffsDB := prefixdb.New(ValidatorPublicKeyDiffsPrefix, validatorsDB) weightsCache, err := metercacher.New( - "sov_weights_cache", + "l1_validator_weights_cache", metricsReg, cache.NewSizedLRU[ids.ID, uint64](execCfg.L1WeightsCacheSize, func(ids.ID, uint64) int { return ids.IDLen + wrappers.LongLen @@ -583,23 +583,23 @@ func New( return nil, err } - inactiveSOVsCache, err := metercacher.New( - "sov_inactive_cache", + inactiveL1ValidatorsCache, err := metercacher.New( + "l1_validator_inactive_cache", metricsReg, - cache.NewSizedLRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]( + cache.NewSizedLRU[ids.ID, maybe.Maybe[L1Validator]]( execCfg.L1InactiveValidatorsCacheSize, - func(_ ids.ID, maybeSOV maybe.Maybe[SubnetOnlyValidator]) int { + func(_ ids.ID, maybeL1Validator maybe.Maybe[L1Validator]) int { const ( - sovOverhead = ids.IDLen + ids.NodeIDLen + 4*wrappers.LongLen + 3*constants.PointerOverhead - maybeSOVOverhead = wrappers.BoolLen + sovOverhead - entryOverhead = ids.IDLen + maybeSOVOverhead + l1ValidatorOverhead = ids.IDLen + ids.NodeIDLen + 4*wrappers.LongLen + 3*constants.PointerOverhead + maybeL1ValidatorOverhead = wrappers.BoolLen + l1ValidatorOverhead + entryOverhead = ids.IDLen + maybeL1ValidatorOverhead ) - if maybeSOV.IsNothing() { + if maybeL1Validator.IsNothing() { return entryOverhead } - sov := maybeSOV.Value() - return entryOverhead + len(sov.PublicKey) + len(sov.RemainingBalanceOwner) + len(sov.DeactivationOwner) + l1Validator := maybeL1Validator.Value() + return entryOverhead + len(l1Validator.PublicKey) + len(l1Validator.RemainingBalanceOwner) + len(l1Validator.DeactivationOwner) }, ), ) @@ -608,7 +608,7 @@ func New( } subnetIDNodeIDCache, err := metercacher.New( - "sov_subnet_id_node_id_cache", + "l1_validator_subnet_id_node_id_cache", metricsReg, cache.NewSizedLRU[subnetIDNodeID, bool](execCfg.L1SubnetIDNodeIDCacheSize, func(subnetIDNodeID, bool) int { return ids.IDLen + ids.NodeIDLen + wrappers.BoolLen @@ -657,11 +657,11 @@ func New( return nil, err } - subnetConversionDB := prefixdb.New(SubnetConversionPrefix, baseDB) - subnetConversionCache, err := metercacher.New[ids.ID, SubnetConversion]( + subnetToL1ConversionDB := prefixdb.New(SubnetToL1ConversionPrefix, baseDB) + subnetToL1ConversionCache, err := metercacher.New[ids.ID, SubnetToL1Conversion]( "subnet_conversion_cache", metricsReg, - cache.NewSizedLRU[ids.ID, SubnetConversion](execCfg.SubnetConversionCacheSize, func(_ ids.ID, c SubnetConversion) int { + cache.NewSizedLRU[ids.ID, SubnetToL1Conversion](execCfg.SubnetToL1ConversionCacheSize, func(_ ids.ID, c SubnetToL1Conversion) int { return 3*ids.IDLen + len(c.Addr) }), ) @@ -727,16 +727,16 @@ func New( expiryDiff: newExpiryDiff(), expiryDB: prefixdb.New(ExpiryReplayProtectionPrefix, baseDB), - activeSOVs: newActiveSubnetOnlyValidators(), - sovDiff: newSubnetOnlyValidatorsDiff(), - subnetOnlyValidatorsDB: subnetOnlyValidatorsDB, - weightsCache: weightsCache, - weightsDB: prefixdb.New(WeightsPrefix, subnetOnlyValidatorsDB), - subnetIDNodeIDCache: subnetIDNodeIDCache, - subnetIDNodeIDDB: prefixdb.New(SubnetIDNodeIDPrefix, subnetOnlyValidatorsDB), - activeDB: prefixdb.New(ActivePrefix, subnetOnlyValidatorsDB), - inactiveCache: inactiveSOVsCache, - inactiveDB: prefixdb.New(InactivePrefix, subnetOnlyValidatorsDB), + activeL1Validators: newActiveL1Validators(), + l1ValidatorsDiff: newL1ValidatorsDiff(), + l1ValidatorsDB: l1ValidatorsDB, + weightsCache: weightsCache, + weightsDB: prefixdb.New(WeightsPrefix, l1ValidatorsDB), + subnetIDNodeIDCache: subnetIDNodeIDCache, + subnetIDNodeIDDB: prefixdb.New(SubnetIDNodeIDPrefix, l1ValidatorsDB), + activeDB: prefixdb.New(ActivePrefix, l1ValidatorsDB), + inactiveCache: inactiveL1ValidatorsCache, + inactiveDB: prefixdb.New(InactivePrefix, l1ValidatorsDB), currentStakers: newBaseStakers(), pendingStakers: newBaseStakers(), @@ -782,9 +782,9 @@ func New( subnetOwnerDB: subnetOwnerDB, subnetOwnerCache: subnetOwnerCache, - subnetConversions: make(map[ids.ID]SubnetConversion), - subnetConversionDB: subnetConversionDB, - subnetConversionCache: subnetConversionCache, + subnetToL1Conversions: make(map[ids.ID]SubnetToL1Conversion), + subnetToL1ConversionDB: subnetToL1ConversionDB, + subnetToL1ConversionCache: subnetToL1ConversionCache, transformedSubnets: make(map[ids.ID]*txs.Tx), transformedSubnetCache: transformedSubnetCache, @@ -836,25 +836,25 @@ func (s *state) DeleteExpiry(entry ExpiryEntry) { func (s *state) GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) { result := make(map[ids.ID]*validators.GetCurrentValidatorOutput) - // First add the current validators (non-SoV) + // First add the current validators (non-L1) for _, staker := range s.currentStakers.validators[subnetID] { if err := ctx.Err(); err != nil { return nil, 0, err } validator := staker.validator result[validator.TxID] = &validators.GetCurrentValidatorOutput{ - ValidationID: validator.TxID, - NodeID: validator.NodeID, - PublicKey: validator.PublicKey, - Weight: validator.Weight, - StartTime: uint64(validator.StartTime.Unix()), - MinNonce: 0, - IsActive: true, - IsSoV: false, + ValidationID: validator.TxID, + NodeID: validator.NodeID, + PublicKey: validator.PublicKey, + Weight: validator.Weight, + StartTime: uint64(validator.StartTime.Unix()), + MinNonce: 0, + IsActive: true, + IsL1Validator: false, } } - // Then iterate over subnetIDNodeID DB and add the SoV validators (if any) + // Then iterate over subnetIDNodeID DB and add the L1 validators (if any) // TODO: consider optimizing this to avoid hitting the subnetIDNodeIDDB and read from actives lookup // if all validators are active (inactive weight is 0) validationIDIter := s.subnetIDNodeIDDB.NewIteratorWithPrefix( @@ -872,38 +872,38 @@ func (s *state) GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (ma return nil, 0, fmt.Errorf("failed to parse validation ID: %w", err) } - vdr, err := s.GetSubnetOnlyValidator(validationID) + vdr, err := s.GetL1Validator(validationID) if err != nil { return nil, 0, fmt.Errorf("failed to get validator: %w", err) } result[validationID] = &validators.GetCurrentValidatorOutput{ - ValidationID: validationID, - NodeID: vdr.NodeID, - PublicKey: bls.PublicKeyFromValidUncompressedBytes(vdr.PublicKey), - Weight: vdr.Weight, - StartTime: vdr.StartTime, - IsActive: vdr.isActive(), - MinNonce: vdr.MinNonce, - IsSoV: true, + ValidationID: validationID, + NodeID: vdr.NodeID, + PublicKey: bls.PublicKeyFromValidUncompressedBytes(vdr.PublicKey), + Weight: vdr.Weight, + StartTime: vdr.StartTime, + IsActive: vdr.isActive(), + MinNonce: vdr.MinNonce, + IsL1Validator: true, } } return result, s.currentHeight, nil } -func (s *state) GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) { - return s.sovDiff.getActiveSubnetOnlyValidatorsIterator( - s.activeSOVs.newIterator(), +func (s *state) GetActiveL1ValidatorsIterator() (iterator.Iterator[L1Validator], error) { + return s.l1ValidatorsDiff.getActiveL1ValidatorsIterator( + s.activeL1Validators.newIterator(), ), nil } -func (s *state) NumActiveSubnetOnlyValidators() int { - return s.activeSOVs.len() + s.sovDiff.netAddedActive +func (s *state) NumActiveL1Validators() int { + return s.activeL1Validators.len() + s.l1ValidatorsDiff.netAddedActive } -func (s *state) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { - if weight, modified := s.sovDiff.modifiedTotalWeight[subnetID]; modified { +func (s *state) WeightOfL1Validators(subnetID ids.ID) (uint64, error) { + if weight, modified := s.l1ValidatorsDiff.modifiedTotalWeight[subnetID]; modified { return weight, nil } @@ -920,31 +920,31 @@ func (s *state) WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) { return weight, nil } -// GetSubnetOnlyValidator allows for concurrent reads. -func (s *state) GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { - if sov, modified := s.sovDiff.modified[validationID]; modified { - if sov.isDeleted() { - return SubnetOnlyValidator{}, database.ErrNotFound +// GetL1Validator allows for concurrent reads. +func (s *state) GetL1Validator(validationID ids.ID) (L1Validator, error) { + if l1Validator, modified := s.l1ValidatorsDiff.modified[validationID]; modified { + if l1Validator.isDeleted() { + return L1Validator{}, database.ErrNotFound } - return sov, nil + return l1Validator, nil } - return s.getPersistedSubnetOnlyValidator(validationID) + return s.getPersistedL1Validator(validationID) } -// getPersistedSubnetOnlyValidator returns the currently persisted -// SubnetOnlyValidator with the given validationID. It is guaranteed that any +// getPersistedL1Validator returns the currently persisted +// L1Validator with the given validationID. It is guaranteed that any // returned validator is either active or inactive (not deleted). -func (s *state) getPersistedSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) { - if sov, ok := s.activeSOVs.get(validationID); ok { - return sov, nil +func (s *state) getPersistedL1Validator(validationID ids.ID) (L1Validator, error) { + if l1Validator, ok := s.activeL1Validators.get(validationID); ok { + return l1Validator, nil } - return getSubnetOnlyValidator(s.inactiveCache, s.inactiveDB, validationID) + return getL1Validator(s.inactiveCache, s.inactiveDB, validationID) } -func (s *state) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { - if has, modified := s.sovDiff.hasSubnetOnlyValidator(subnetID, nodeID); modified { +func (s *state) HasL1Validator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) { + if has, modified := s.l1ValidatorsDiff.hasL1Validator(subnetID, nodeID); modified { return has, nil } @@ -966,8 +966,8 @@ func (s *state) HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool return has, nil } -func (s *state) PutSubnetOnlyValidator(sov SubnetOnlyValidator) error { - return s.sovDiff.putSubnetOnlyValidator(s, sov) +func (s *state) PutL1Validator(l1Validator L1Validator) error { + return s.l1ValidatorsDiff.putL1Validator(s, l1Validator) } func (s *state) GetCurrentValidator(subnetID ids.ID, nodeID ids.NodeID) (*Staker, error) { @@ -1109,31 +1109,31 @@ func (s *state) SetSubnetOwner(subnetID ids.ID, owner fx.Owner) { s.subnetOwners[subnetID] = owner } -// GetSubnetConversion allows for concurrent reads. -func (s *state) GetSubnetConversion(subnetID ids.ID) (SubnetConversion, error) { - if c, ok := s.subnetConversions[subnetID]; ok { +// GetSubnetToL1Conversion allows for concurrent reads. +func (s *state) GetSubnetToL1Conversion(subnetID ids.ID) (SubnetToL1Conversion, error) { + if c, ok := s.subnetToL1Conversions[subnetID]; ok { return c, nil } - if c, ok := s.subnetConversionCache.Get(subnetID); ok { + if c, ok := s.subnetToL1ConversionCache.Get(subnetID); ok { return c, nil } - bytes, err := s.subnetConversionDB.Get(subnetID[:]) + bytes, err := s.subnetToL1ConversionDB.Get(subnetID[:]) if err != nil { - return SubnetConversion{}, err + return SubnetToL1Conversion{}, err } - var c SubnetConversion + var c SubnetToL1Conversion if _, err := block.GenesisCodec.Unmarshal(bytes, &c); err != nil { - return SubnetConversion{}, err + return SubnetToL1Conversion{}, err } - s.subnetConversionCache.Put(subnetID, c) + s.subnetToL1ConversionCache.Put(subnetID, c) return c, nil } -func (s *state) SetSubnetConversion(subnetID ids.ID, c SubnetConversion) { - s.subnetConversions[subnetID] = c +func (s *state) SetSubnetToL1Conversion(subnetID ids.ID, c SubnetToL1Conversion) { + s.subnetToL1Conversions[subnetID] = c } func (s *state) GetSubnetTransformation(subnetID ids.ID) (*txs.Tx, error) { @@ -1347,12 +1347,12 @@ func (s *state) SetFeeState(feeState gas.State) { s.feeState = feeState } -func (s *state) GetSoVExcess() gas.Gas { - return s.sovExcess +func (s *state) GetL1ValidatorExcess() gas.Gas { + return s.l1ValidatorExcess } -func (s *state) SetSoVExcess(e gas.Gas) { - s.sovExcess = e +func (s *state) SetL1ValidatorExcess(e gas.Gas) { + s.l1ValidatorExcess = e } func (s *state) GetAccruedFees() uint64 { @@ -1635,7 +1635,7 @@ func (s *state) load() error { return errors.Join( s.loadMetadata(), s.loadExpiry(), - s.loadActiveSubnetOnlyValidators(), + s.loadActiveL1Validators(), s.loadCurrentValidators(), s.loadPendingValidators(), s.initValidatorSets(), @@ -1657,12 +1657,12 @@ func (s *state) loadMetadata() error { s.persistedFeeState = feeState s.SetFeeState(feeState) - sovExcess, err := database.WithDefault(database.GetUInt64, s.singletonDB, SoVExcessKey, 0) + l1ValidatorExcess, err := database.WithDefault(database.GetUInt64, s.singletonDB, L1ValidatorExcessKey, 0) if err != nil { return err } - s.persistedSOVExcess = gas.Gas(sovExcess) - s.SetSoVExcess(gas.Gas(sovExcess)) + s.persistedL1ValidatorExcess = gas.Gas(l1ValidatorExcess) + s.SetL1ValidatorExcess(gas.Gas(l1ValidatorExcess)) accruedFees, err := database.WithDefault(database.GetUInt64, s.singletonDB, AccruedFeesKey, 0) if err != nil { @@ -1731,7 +1731,7 @@ func (s *state) loadExpiry() error { return nil } -func (s *state) loadActiveSubnetOnlyValidators() error { +func (s *state) loadActiveL1Validators() error { it := s.activeDB.NewIterator() defer it.Release() for it.Next() { @@ -1742,16 +1742,16 @@ func (s *state) loadActiveSubnetOnlyValidators() error { } var ( - value = it.Value() - sov = SubnetOnlyValidator{ + value = it.Value() + l1Validator = L1Validator{ ValidationID: validationID, } ) - if _, err := block.GenesisCodec.Unmarshal(value, &sov); err != nil { - return fmt.Errorf("failed to unmarshal SubnetOnlyValidator: %w", err) + if _, err := block.GenesisCodec.Unmarshal(value, &l1Validator); err != nil { + return fmt.Errorf("failed to unmarshal L1 validator: %w", err) } - s.activeSOVs.put(sov) + s.activeL1Validators.put(l1Validator) } return nil @@ -2011,7 +2011,7 @@ func (s *state) loadPendingValidators() error { ) } -// Invariant: initValidatorSets requires loadActiveSubnetOnlyValidators and +// Invariant: initValidatorSets requires loadActiveL1Validators and // loadCurrentValidators to have already been called. func (s *state) initValidatorSets() error { if s.validators.NumSubnets() != 0 { @@ -2020,7 +2020,7 @@ func (s *state) initValidatorSets() error { } // Load active ACP-77 validators - if err := s.activeSOVs.addStakersToValidatorManager(s.validators); err != nil { + if err := s.activeL1Validators.addStakersToValidatorManager(s.validators); err != nil { return err } @@ -2041,7 +2041,7 @@ func (s *state) initValidatorSets() error { return err } - // It is required for the SoVs to be loaded first so that the total + // It is required for the L1 validators to be loaded first so that the total // weight is equal to the active weights here. activeWeight, err := s.validators.TotalWeight(subnetID) if err != nil { @@ -2117,13 +2117,13 @@ func (s *state) write(updateValidators bool, height uint64) error { s.writeCurrentStakers(codecVersion), s.writePendingStakers(), s.WriteValidatorMetadata(s.currentValidatorList, s.currentSubnetValidatorList, codecVersion), // Must be called after writeCurrentStakers - s.writeSubnetOnlyValidators(), + s.writeL1Validators(), s.writeTXs(), s.writeRewardUTXOs(), s.writeUTXOs(), s.writeSubnets(), s.writeSubnetOwners(), - s.writeSubnetConversions(), + s.writeSubnetToL1Conversions(), s.writeTransformedSubnets(), s.writeSubnetSupplies(), s.writeChains(), @@ -2138,7 +2138,7 @@ func (s *state) Close() error { s.subnetIDNodeIDDB.Close(), s.activeDB.Close(), s.inactiveDB.Close(), - s.subnetOnlyValidatorsDB.Close(), + s.l1ValidatorsDB.Close(), s.pendingSubnetValidatorBaseDB.Close(), s.pendingSubnetDelegatorBaseDB.Close(), s.pendingDelegatorBaseDB.Close(), @@ -2154,7 +2154,7 @@ func (s *state) Close() error { s.rewardUTXODB.Close(), s.utxoDB.Close(), s.subnetBaseDB.Close(), - s.subnetConversionDB.Close(), + s.subnetToL1ConversionDB.Close(), s.transformedSubnetDB.Close(), s.supplyDB.Close(), s.chainDB.Close(), @@ -2388,7 +2388,7 @@ func (s *state) getInheritedPublicKey(nodeID ids.NodeID) (*bls.PublicKey, error) // validator set changes. // // This function must be called prior to writeCurrentStakers and -// writeSubnetOnlyValidators. +// writeL1Validators. // // TODO: L1s with no active weight should not be held in memory. func (s *state) updateValidatorManager(updateValidators bool) error { @@ -2442,15 +2442,15 @@ func (s *state) updateValidatorManager(updateValidators bool) error { } } - // Remove all deleted SoV validators. This must be done before adding new - // SoV validators to support the case where a validator is removed and then + // Remove all deleted L1 validators. This must be done before adding new + // L1 validators to support the case where a validator is removed and then // immediately re-added with a different validationID. - for validationID, sov := range s.sovDiff.modified { - if !sov.isDeleted() { + for validationID, l1Validator := range s.l1ValidatorsDiff.modified { + if !l1Validator.isDeleted() { continue } - priorSOV, err := s.getPersistedSubnetOnlyValidator(validationID) + priorL1Validator, err := s.getPersistedL1Validator(validationID) if err == database.ErrNotFound { // Deleting a non-existent validator is a noop. This can happen if // the validator was added and then immediately removed. @@ -2460,41 +2460,41 @@ func (s *state) updateValidatorManager(updateValidators bool) error { return err } - if err := s.validators.RemoveWeight(priorSOV.SubnetID, priorSOV.effectiveNodeID(), priorSOV.Weight); err != nil { + if err := s.validators.RemoveWeight(priorL1Validator.SubnetID, priorL1Validator.effectiveNodeID(), priorL1Validator.Weight); err != nil { return err } } - // Now that the removed SoV validators have been deleted, perform additions + // Now that the removed L1 validators have been deleted, perform additions // and modifications. - for validationID, sov := range s.sovDiff.modified { - if sov.isDeleted() { + for validationID, l1Validator := range s.l1ValidatorsDiff.modified { + if l1Validator.isDeleted() { continue } - priorSOV, err := s.getPersistedSubnetOnlyValidator(validationID) + priorL1Validator, err := s.getPersistedL1Validator(validationID) switch err { case nil: // Modifying an existing validator - if priorSOV.isActive() == sov.isActive() { + if priorL1Validator.isActive() == l1Validator.isActive() { // This validator's active status isn't changing. This means // the effectiveNodeIDs are equal. - nodeID := sov.effectiveNodeID() - if priorSOV.Weight < sov.Weight { - err = s.validators.AddWeight(sov.SubnetID, nodeID, sov.Weight-priorSOV.Weight) - } else if priorSOV.Weight > sov.Weight { - err = s.validators.RemoveWeight(sov.SubnetID, nodeID, priorSOV.Weight-sov.Weight) + nodeID := l1Validator.effectiveNodeID() + if priorL1Validator.Weight < l1Validator.Weight { + err = s.validators.AddWeight(l1Validator.SubnetID, nodeID, l1Validator.Weight-priorL1Validator.Weight) + } else if priorL1Validator.Weight > l1Validator.Weight { + err = s.validators.RemoveWeight(l1Validator.SubnetID, nodeID, priorL1Validator.Weight-l1Validator.Weight) } } else { // This validator's active status is changing. err = errors.Join( - s.validators.RemoveWeight(sov.SubnetID, priorSOV.effectiveNodeID(), priorSOV.Weight), - addSoVToValidatorManager(s.validators, sov), + s.validators.RemoveWeight(l1Validator.SubnetID, priorL1Validator.effectiveNodeID(), priorL1Validator.Weight), + addL1ValidatorToValidatorManager(s.validators, l1Validator), ) } case database.ErrNotFound: // Adding a new validator - err = addSoVToValidatorManager(s.validators, sov) + err = addL1ValidatorToValidatorManager(s.validators, l1Validator) } if err != nil { return err @@ -2562,39 +2562,39 @@ func (s *state) calculateValidatorDiffs() (map[subnetIDNodeID]*validatorDiff, er } // Calculate the changes to the ACP-77 validator set - for validationID, sov := range s.sovDiff.modified { - priorSOV, err := s.getPersistedSubnetOnlyValidator(validationID) + for validationID, l1Validator := range s.l1ValidatorsDiff.modified { + priorL1Validator, err := s.getPersistedL1Validator(validationID) if err == nil { // Delete the prior validator subnetIDNodeID := subnetIDNodeID{ - subnetID: priorSOV.SubnetID, - nodeID: priorSOV.effectiveNodeID(), + subnetID: priorL1Validator.SubnetID, + nodeID: priorL1Validator.effectiveNodeID(), } diff := getOrSetDefault(changes, subnetIDNodeID) - if err := diff.weightDiff.Sub(priorSOV.Weight); err != nil { + if err := diff.weightDiff.Sub(priorL1Validator.Weight); err != nil { return nil, err } - diff.prevPublicKey = priorSOV.effectivePublicKeyBytes() + diff.prevPublicKey = priorL1Validator.effectivePublicKeyBytes() } if err != database.ErrNotFound && err != nil { return nil, err } // If the validator is being removed, we shouldn't work to re-add it. - if sov.isDeleted() { + if l1Validator.isDeleted() { continue } // Add the new validator subnetIDNodeID := subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.effectiveNodeID(), + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.effectiveNodeID(), } diff := getOrSetDefault(changes, subnetIDNodeID) - if err := diff.weightDiff.Add(sov.Weight); err != nil { + if err := diff.weightDiff.Add(l1Validator.Weight); err != nil { return nil, err } - diff.newPublicKey = sov.effectivePublicKeyBytes() + diff.newPublicKey = l1Validator.effectivePublicKeyBytes() } return changes, nil @@ -2801,9 +2801,9 @@ func writePendingDiff( return nil } -func (s *state) writeSubnetOnlyValidators() error { +func (s *state) writeL1Validators() error { // Write modified weights - for subnetID, weight := range s.sovDiff.modifiedTotalWeight { + for subnetID, weight := range s.l1ValidatorsDiff.modifiedTotalWeight { var err error if weight == 0 { err = s.weightsDB.Delete(subnetID[:]) @@ -2817,30 +2817,30 @@ func (s *state) writeSubnetOnlyValidators() error { s.weightsCache.Put(subnetID, weight) } - // The SoV diff application is split into two loops to ensure that all + // The L1 validator diff application is split into two loops to ensure that all // deletions to the subnetIDNodeIDDB happen prior to any additions. - // Otherwise replacing an SoV by deleting it and then re-adding it with a + // Otherwise replacing an L1 validator by deleting it and then re-adding it with a // different validationID could result in an inconsistent state. - for validationID, sov := range s.sovDiff.modified { + for validationID, l1Validator := range s.l1ValidatorsDiff.modified { // Delete the prior validator if it exists var err error - if s.activeSOVs.delete(validationID) { - err = deleteSubnetOnlyValidator(s.activeDB, emptySoVCache, validationID) + if s.activeL1Validators.delete(validationID) { + err = deleteL1Validator(s.activeDB, emptyL1ValidatorCache, validationID) } else { - err = deleteSubnetOnlyValidator(s.inactiveDB, s.inactiveCache, validationID) + err = deleteL1Validator(s.inactiveDB, s.inactiveCache, validationID) } if err != nil { return err } - if !sov.isDeleted() { + if !l1Validator.isDeleted() { continue } var ( subnetIDNodeID = subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.NodeID, + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.NodeID, } subnetIDNodeIDKey = subnetIDNodeID.Marshal() ) @@ -2851,16 +2851,16 @@ func (s *state) writeSubnetOnlyValidators() error { s.subnetIDNodeIDCache.Put(subnetIDNodeID, false) } - for validationID, sov := range s.sovDiff.modified { - if sov.isDeleted() { + for validationID, l1Validator := range s.l1ValidatorsDiff.modified { + if l1Validator.isDeleted() { continue } // Update the subnetIDNodeID mapping var ( subnetIDNodeID = subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.NodeID, + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.NodeID, } subnetIDNodeIDKey = subnetIDNodeID.Marshal() ) @@ -2872,18 +2872,18 @@ func (s *state) writeSubnetOnlyValidators() error { // Add the new validator var err error - if sov.isActive() { - s.activeSOVs.put(sov) - err = putSubnetOnlyValidator(s.activeDB, emptySoVCache, sov) + if l1Validator.isActive() { + s.activeL1Validators.put(l1Validator) + err = putL1Validator(s.activeDB, emptyL1ValidatorCache, l1Validator) } else { - err = putSubnetOnlyValidator(s.inactiveDB, s.inactiveCache, sov) + err = putL1Validator(s.inactiveDB, s.inactiveCache, l1Validator) } if err != nil { return err } } - s.sovDiff = newSubnetOnlyValidatorsDiff() + s.l1ValidatorsDiff = newL1ValidatorsDiff() return nil } @@ -2986,18 +2986,18 @@ func (s *state) writeSubnetOwners() error { return nil } -func (s *state) writeSubnetConversions() error { - for subnetID, c := range s.subnetConversions { - delete(s.subnetConversions, subnetID) +func (s *state) writeSubnetToL1Conversions() error { + for subnetID, c := range s.subnetToL1Conversions { + delete(s.subnetToL1Conversions, subnetID) bytes, err := block.GenesisCodec.Marshal(block.CodecVersion, &c) if err != nil { return fmt.Errorf("failed to marshal subnet conversion: %w", err) } - s.subnetConversionCache.Put(subnetID, c) + s.subnetToL1ConversionCache.Put(subnetID, c) - if err := s.subnetConversionDB.Put(subnetID[:], bytes); err != nil { + if err := s.subnetToL1ConversionDB.Put(subnetID[:], bytes); err != nil { return fmt.Errorf("failed to write subnet conversion: %w", err) } } @@ -3066,11 +3066,11 @@ func (s *state) writeMetadata(height uint64) error { } s.persistedFeeState = s.feeState } - if s.sovExcess != s.persistedSOVExcess { - if err := database.PutUInt64(s.singletonDB, SoVExcessKey, uint64(s.sovExcess)); err != nil { - return fmt.Errorf("failed to write sov excess: %w", err) + if s.l1ValidatorExcess != s.persistedL1ValidatorExcess { + if err := database.PutUInt64(s.singletonDB, L1ValidatorExcessKey, uint64(s.l1ValidatorExcess)); err != nil { + return fmt.Errorf("failed to write l1Validator excess: %w", err) } - s.persistedSOVExcess = s.sovExcess + s.persistedL1ValidatorExcess = s.l1ValidatorExcess } if s.accruedFees != s.persistedAccruedFees { if err := database.PutUInt64(s.singletonDB, AccruedFeesKey, s.accruedFees); err != nil { diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 7ffe6541a536..3636046cabdc 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -1204,21 +1204,21 @@ func TestStateSubnetOwner(t *testing.T) { require.Equal(owner2, owner) } -func TestStateSubnetConversion(t *testing.T) { +func TestStateSubnetToL1Conversion(t *testing.T) { tests := []struct { name string - setup func(s *state, subnetID ids.ID, c SubnetConversion) + setup func(s *state, subnetID ids.ID, c SubnetToL1Conversion) }{ { name: "in-memory", - setup: func(s *state, subnetID ids.ID, c SubnetConversion) { - s.SetSubnetConversion(subnetID, c) + setup: func(s *state, subnetID ids.ID, c SubnetToL1Conversion) { + s.SetSubnetToL1Conversion(subnetID, c) }, }, { name: "cache", - setup: func(s *state, subnetID ids.ID, c SubnetConversion) { - s.subnetConversionCache.Put(subnetID, c) + setup: func(s *state, subnetID ids.ID, c SubnetToL1Conversion) { + s.subnetToL1ConversionCache.Put(subnetID, c) }, }, } @@ -1228,20 +1228,20 @@ func TestStateSubnetConversion(t *testing.T) { require = require.New(t) state = newTestState(t, memdb.New()) subnetID = ids.GenerateTestID() - expectedConversion = SubnetConversion{ + expectedConversion = SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: []byte{'a', 'd', 'd', 'r'}, } ) - actualConversion, err := state.GetSubnetConversion(subnetID) + actualConversion, err := state.GetSubnetToL1Conversion(subnetID) require.ErrorIs(err, database.ErrNotFound) require.Zero(actualConversion) test.setup(state, subnetID, expectedConversion) - actualConversion, err = state.GetSubnetConversion(subnetID) + actualConversion, err = state.GetSubnetToL1Conversion(subnetID) require.NoError(err) require.Equal(expectedConversion, actualConversion) }) @@ -1355,20 +1355,21 @@ func TestStateFeeStateCommitAndLoad(t *testing.T) { require.Equal(expectedFeeState, s.GetFeeState()) } -// Verify that committing the state writes the sov excess to the database and -// that loading the state fetches the sov excess from the database. -func TestStateSoVExcessCommitAndLoad(t *testing.T) { +// Verify that committing the state writes the L1 validator excess to the +// database and that loading the state fetches the L1 validator excess from the +// database. +func TestStateL1ValidatorExcessCommitAndLoad(t *testing.T) { require := require.New(t) db := memdb.New() s := newTestState(t, db) - const expectedSoVExcess gas.Gas = 10 - s.SetSoVExcess(expectedSoVExcess) + const expectedL1ValidatorExcess gas.Gas = 10 + s.SetL1ValidatorExcess(expectedL1ValidatorExcess) require.NoError(s.Commit()) s = newTestState(t, db) - require.Equal(expectedSoVExcess, s.GetSoVExcess()) + require.Equal(expectedL1ValidatorExcess, s.GetL1ValidatorExcess()) } // Verify that committing the state writes the accrued fees to the database and @@ -1506,8 +1507,8 @@ func TestStateExpiryCommitAndLoad(t *testing.T) { require.False(has) } -func TestSubnetOnlyValidators(t *testing.T) { - sov := SubnetOnlyValidator{ +func TestL1Validators(t *testing.T) { + l1Validator := L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -1524,20 +1525,20 @@ func TestSubnetOnlyValidators(t *testing.T) { otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) tests := []struct { - name string - initial []SubnetOnlyValidator - sovs []SubnetOnlyValidator + name string + initial []L1Validator + l1Validators []L1Validator }{ { name: "empty noop", }, { name: "initially active not modified", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active @@ -1546,7 +1547,7 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "initially inactive not modified", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), @@ -1559,21 +1560,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "initially active removed", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 0, // Removed }, @@ -1581,21 +1582,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "initially inactive removed", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 0, // Inactive }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 0, // Removed }, @@ -1603,21 +1604,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "increase active weight", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 2, // Increased EndAccumulatedFee: 1, // Active @@ -1626,21 +1627,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "decrease active weight", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 2, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Decreased EndAccumulatedFee: 1, // Active @@ -1649,21 +1650,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "deactivate", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 0, // Inactive @@ -1672,21 +1673,21 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "reactivate", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 0, // Inactive }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active @@ -1695,29 +1696,29 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "update multiple times", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 2, // Not removed EndAccumulatedFee: 1, // Active }, { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 3, // Not removed EndAccumulatedFee: 1, // Active @@ -1726,28 +1727,28 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "change validationID", - initial: []SubnetOnlyValidator{ + initial: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 0, // Removed }, { ValidationID: ids.GenerateTestID(), - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: otherPKBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active @@ -1756,19 +1757,19 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "added and removed", - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 1, // Active }, { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 0, // Removed }, @@ -1776,19 +1777,19 @@ func TestSubnetOnlyValidators(t *testing.T) { }, { name: "add multiple inactive", - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), - SubnetID: sov.SubnetID, + SubnetID: l1Validator.SubnetID, NodeID: ids.GenerateTestNodeID(), PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 0, // Inactive }, { - ValidationID: sov.ValidationID, - SubnetID: sov.SubnetID, - NodeID: sov.NodeID, + ValidationID: l1Validator.ValidationID, + SubnetID: l1Validator.SubnetID, + NodeID: l1Validator.NodeID, PublicKey: pkBytes, Weight: 1, // Not removed EndAccumulatedFee: 0, // Inactive @@ -1805,19 +1806,19 @@ func TestSubnetOnlyValidators(t *testing.T) { state := newTestState(t, db) var ( - initialSOVs = make(map[ids.ID]SubnetOnlyValidator) - subnetIDs set.Set[ids.ID] + initialL1Validators = make(map[ids.ID]L1Validator) + subnetIDs set.Set[ids.ID] ) - for _, sov := range test.initial { + for _, l1Validator := range test.initial { // The codec creates zero length slices rather than leaving them // as nil, so we need to populate the slices for later reflect // based equality checks. - sov.RemainingBalanceOwner = []byte{} - sov.DeactivationOwner = []byte{} + l1Validator.RemainingBalanceOwner = []byte{} + l1Validator.DeactivationOwner = []byte{} - require.NoError(state.PutSubnetOnlyValidator(sov)) - initialSOVs[sov.ValidationID] = sov - subnetIDs.Add(sov.SubnetID) + require.NoError(state.PutL1Validator(l1Validator)) + initialL1Validators[l1Validator.ValidationID] = l1Validator + subnetIDs.Add(l1Validator.SubnetID) } state.SetHeight(0) @@ -1826,62 +1827,62 @@ func TestSubnetOnlyValidators(t *testing.T) { d, err := NewDiffOn(state) require.NoError(err) - expectedSOVs := maps.Clone(initialSOVs) - for _, sov := range test.sovs { - sov.RemainingBalanceOwner = []byte{} - sov.DeactivationOwner = []byte{} + expectedL1Validators := maps.Clone(initialL1Validators) + for _, l1Validator := range test.l1Validators { + l1Validator.RemainingBalanceOwner = []byte{} + l1Validator.DeactivationOwner = []byte{} - require.NoError(d.PutSubnetOnlyValidator(sov)) - expectedSOVs[sov.ValidationID] = sov - subnetIDs.Add(sov.SubnetID) + require.NoError(d.PutL1Validator(l1Validator)) + expectedL1Validators[l1Validator.ValidationID] = l1Validator + subnetIDs.Add(l1Validator.SubnetID) } verifyChain := func(chain Chain) { - for _, expectedSOV := range expectedSOVs { - if !expectedSOV.isDeleted() { + for _, expectedL1Validator := range expectedL1Validators { + if !expectedL1Validator.isDeleted() { continue } - sov, err := chain.GetSubnetOnlyValidator(expectedSOV.ValidationID) + l1Validator, err := chain.GetL1Validator(expectedL1Validator.ValidationID) require.ErrorIs(err, database.ErrNotFound) - require.Zero(sov) + require.Zero(l1Validator) } var ( weights = make(map[ids.ID]uint64) - expectedActive []SubnetOnlyValidator + expectedActive []L1Validator ) - for _, expectedSOV := range expectedSOVs { - if expectedSOV.isDeleted() { + for _, expectedL1Validator := range expectedL1Validators { + if expectedL1Validator.isDeleted() { continue } - sov, err := chain.GetSubnetOnlyValidator(expectedSOV.ValidationID) + l1Validator, err := chain.GetL1Validator(expectedL1Validator.ValidationID) require.NoError(err) - require.Equal(expectedSOV, sov) + require.Equal(expectedL1Validator, l1Validator) - has, err := chain.HasSubnetOnlyValidator(expectedSOV.SubnetID, expectedSOV.NodeID) + has, err := chain.HasL1Validator(expectedL1Validator.SubnetID, expectedL1Validator.NodeID) require.NoError(err) require.True(has) - weights[sov.SubnetID] += sov.Weight - if expectedSOV.isActive() { - expectedActive = append(expectedActive, expectedSOV) + weights[l1Validator.SubnetID] += l1Validator.Weight + if expectedL1Validator.isActive() { + expectedActive = append(expectedActive, expectedL1Validator) } } utils.Sort(expectedActive) - activeIterator, err := chain.GetActiveSubnetOnlyValidatorsIterator() + activeIterator, err := chain.GetActiveL1ValidatorsIterator() require.NoError(err) require.Equal( expectedActive, iterator.ToSlice(activeIterator), ) - require.Equal(len(expectedActive), chain.NumActiveSubnetOnlyValidators()) + require.Equal(len(expectedActive), chain.NumActiveL1Validators()) for subnetID, expectedWeight := range weights { - weight, err := chain.WeightOfSubnetOnlyValidators(subnetID) + weight, err := chain.WeightOfL1Validators(subnetID) require.NoError(err) require.Equal(expectedWeight, weight) } @@ -1901,30 +1902,30 @@ func TestSubnetOnlyValidators(t *testing.T) { // Verify that the subnetID+nodeID -> validationID mapping is correct. var populatedSubnetIDNodeIDs set.Set[subnetIDNodeID] - for _, sov := range expectedSOVs { - if sov.isDeleted() { + for _, l1Validator := range expectedL1Validators { + if l1Validator.isDeleted() { continue } subnetIDNodeID := subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.NodeID, + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.NodeID, } populatedSubnetIDNodeIDs.Add(subnetIDNodeID) subnetIDNodeIDKey := subnetIDNodeID.Marshal() validatorID, err := database.GetID(state.subnetIDNodeIDDB, subnetIDNodeIDKey) require.NoError(err) - require.Equal(sov.ValidationID, validatorID) + require.Equal(l1Validator.ValidationID, validatorID) } - for _, sov := range expectedSOVs { - if !sov.isDeleted() { + for _, l1Validator := range expectedL1Validators { + if !l1Validator.isDeleted() { continue } subnetIDNodeID := subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.NodeID, + subnetID: l1Validator.SubnetID, + nodeID: l1Validator.NodeID, } if populatedSubnetIDNodeIDs.Contains(subnetIDNodeID) { continue @@ -1936,33 +1937,33 @@ func TestSubnetOnlyValidators(t *testing.T) { require.False(has) } - sovsToValidatorSet := func( - sovs map[ids.ID]SubnetOnlyValidator, + l1ValdiatorsToValidatorSet := func( + l1Validators map[ids.ID]L1Validator, subnetID ids.ID, ) map[ids.NodeID]*validators.GetValidatorOutput { validatorSet := make(map[ids.NodeID]*validators.GetValidatorOutput) - for _, sov := range sovs { - if sov.SubnetID != subnetID || sov.isDeleted() { + for _, l1Validator := range l1Validators { + if l1Validator.SubnetID != subnetID || l1Validator.isDeleted() { continue } - nodeID := sov.effectiveNodeID() + nodeID := l1Validator.effectiveNodeID() vdr, ok := validatorSet[nodeID] if !ok { vdr = &validators.GetValidatorOutput{ NodeID: nodeID, - PublicKey: sov.effectivePublicKey(), + PublicKey: l1Validator.effectivePublicKey(), } validatorSet[nodeID] = vdr } - vdr.Weight += sov.Weight + vdr.Weight += l1Validator.Weight } return validatorSet } reloadedState := newTestState(t, db) for subnetID := range subnetIDs { - expectedEndValidatorSet := sovsToValidatorSet(expectedSOVs, subnetID) + expectedEndValidatorSet := l1ValdiatorsToValidatorSet(expectedL1Validators, subnetID) endValidatorSet := state.validators.GetMap(subnetID) require.Equal(expectedEndValidatorSet, endValidatorSet) @@ -1972,17 +1973,16 @@ func TestSubnetOnlyValidators(t *testing.T) { require.NoError(state.ApplyValidatorWeightDiffs(context.Background(), endValidatorSet, 1, 1, subnetID)) require.NoError(state.ApplyValidatorPublicKeyDiffs(context.Background(), endValidatorSet, 1, 1, subnetID)) - initialValidatorSet := sovsToValidatorSet(initialSOVs, subnetID) + initialValidatorSet := l1ValdiatorsToValidatorSet(initialL1Validators, subnetID) require.Equal(initialValidatorSet, endValidatorSet) } }) } } -// TestLoadSubnetOnlyValidatorAndLegacy tests that the state can be loaded when -// there is a mix of legacy validators and subnet-only validators in the same -// subnet. -func TestLoadSubnetOnlyValidatorAndLegacy(t *testing.T) { +// TestLoadL1ValidatorAndLegacy tests that the state can be loaded when there is +// a mix of legacy validators and L1 validators in the same subnet. +func TestLoadL1ValidatorAndLegacy(t *testing.T) { var ( require = require.New(t) db = memdb.New() @@ -2021,7 +2021,7 @@ func TestLoadSubnetOnlyValidatorAndLegacy(t *testing.T) { pk := bls.PublicFromSecretKey(sk) pkBytes := bls.PublicKeyToUncompressedBytes(pk) - sov := SubnetOnlyValidator{ + l1Validator := L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: legacyStaker.SubnetID, NodeID: ids.GenerateTestNodeID(), @@ -2033,7 +2033,7 @@ func TestLoadSubnetOnlyValidatorAndLegacy(t *testing.T) { MinNonce: 3, EndAccumulatedFee: 4, } - require.NoError(state.PutSubnetOnlyValidator(sov)) + require.NoError(state.PutL1Validator(l1Validator)) state.SetHeight(1) require.NoError(state.Commit()) @@ -2046,9 +2046,9 @@ func TestLoadSubnetOnlyValidatorAndLegacy(t *testing.T) { require.Equal(expectedValidatorSet, validatorSet) } -// TestSubnetOnlyValidatorAfterLegacyRemoval verifies that a legacy validator -// can be replaced by an SoV in the same block. -func TestSubnetOnlyValidatorAfterLegacyRemoval(t *testing.T) { +// TestL1ValidatorAfterLegacyRemoval verifies that a legacy validator can be +// replaced by an L1 validator in the same block. +func TestL1ValidatorAfterLegacyRemoval(t *testing.T) { require := require.New(t) db := memdb.New() @@ -2071,7 +2071,7 @@ func TestSubnetOnlyValidatorAfterLegacyRemoval(t *testing.T) { state.DeleteCurrentValidator(legacyStaker) - sov := SubnetOnlyValidator{ + l1Validator := L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: legacyStaker.SubnetID, NodeID: legacyStaker.NodeID, @@ -2083,7 +2083,7 @@ func TestSubnetOnlyValidatorAfterLegacyRemoval(t *testing.T) { MinNonce: 3, EndAccumulatedFee: 4, } - require.NoError(state.PutSubnetOnlyValidator(sov)) + require.NoError(state.PutL1Validator(l1Validator)) state.SetHeight(2) require.NoError(state.Commit()) @@ -2106,9 +2106,9 @@ func TestGetCurrentValidators(t *testing.T) { now := time.Now() tests := []struct { - name string - initial []*Staker - sovs []SubnetOnlyValidator + name string + initial []*Staker + l1Validators []L1Validator }{ { name: "empty noop", @@ -2156,8 +2156,8 @@ func TestGetCurrentValidators(t *testing.T) { }, }, { - name: "sovs only in same subnet", - sovs: []SubnetOnlyValidator{ + name: "L1 validators with the same SubnetID", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: subnetID1, @@ -2177,8 +2177,8 @@ func TestGetCurrentValidators(t *testing.T) { }, }, { - name: "sovs only in different subnets", - sovs: []SubnetOnlyValidator{ + name: "L1 validators with different SubnetIDs", + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: subnetID1, @@ -2198,7 +2198,7 @@ func TestGetCurrentValidators(t *testing.T) { }, }, { - name: "initial stakers and sovs mixed", + name: "initial stakers and L1 validators mixed", initial: []*Staker{ { TxID: ids.GenerateTestID(), @@ -2225,7 +2225,7 @@ func TestGetCurrentValidators(t *testing.T) { StartTime: now, }, }, - sovs: []SubnetOnlyValidator{ + l1Validators: []L1Validator{ { ValidationID: ids.GenerateTestID(), SubnetID: subnetID1, @@ -2288,14 +2288,14 @@ func TestGetCurrentValidators(t *testing.T) { require.NoError(state.PutCurrentValidator(staker)) } - for _, sov := range test.sovs { + for _, l1Validator := range test.l1Validators { // The codec creates zero length slices rather than leaving them // as nil, so we need to populate the slices for later reflect // based equality checks. - sov.RemainingBalanceOwner = []byte{} - sov.DeactivationOwner = []byte{} + l1Validator.RemainingBalanceOwner = []byte{} + l1Validator.DeactivationOwner = []byte{} - require.NoError(state.PutSubnetOnlyValidator(sov)) + require.NoError(state.PutL1Validator(l1Validator)) } state.SetHeight(0) @@ -2307,20 +2307,20 @@ func TestGetCurrentValidators(t *testing.T) { stakersBySubnetID[staker.SubnetID] = append(stakers, staker) } - sovBySubnetID := make(map[ids.ID][]SubnetOnlyValidator) - for _, sov := range test.sovs { - if sov.Weight == 0 { + l1ValidatorsBySubnetID := make(map[ids.ID][]L1Validator) + for _, l1Validator := range test.l1Validators { + if l1Validator.Weight == 0 { continue } - sovs := sovBySubnetID[sov.SubnetID] - sovBySubnetID[sov.SubnetID] = append(sovs, sov) + l1Validators := l1ValidatorsBySubnetID[l1Validator.SubnetID] + l1ValidatorsBySubnetID[l1Validator.SubnetID] = append(l1Validators, l1Validator) } for _, subnetID := range subnetIDs { currentValidators, height, err := state.GetCurrentValidatorSet(context.Background(), subnetID) require.NoError(err) require.Equal(uint64(0), height) - totalLen := len(stakersBySubnetID[subnetID]) + len(sovBySubnetID[subnetID]) + totalLen := len(stakersBySubnetID[subnetID]) + len(l1ValidatorsBySubnetID[subnetID]) require.Len(currentValidators, totalLen) for _, expectedStaker := range stakersBySubnetID[subnetID] { @@ -2333,20 +2333,20 @@ func TestGetCurrentValidators(t *testing.T) { require.Equal(uint64(expectedStaker.StartTime.Unix()), currentValidator.StartTime) require.Equal(uint64(0), currentValidator.MinNonce) require.True(currentValidator.IsActive) - require.False(currentValidator.IsSoV) + require.False(currentValidator.IsL1Validator) } - for _, expectedSOV := range sovBySubnetID[subnetID] { - currentValidator, ok := currentValidators[expectedSOV.ValidationID] + for _, expectedL1Validator := range l1ValidatorsBySubnetID[subnetID] { + currentValidator, ok := currentValidators[expectedL1Validator.ValidationID] require.True(ok) - require.Equal(expectedSOV.ValidationID, currentValidator.ValidationID) - require.Equal(expectedSOV.NodeID, currentValidator.NodeID) - require.Equal(expectedSOV.PublicKey, currentValidator.PublicKey.Serialize()) - require.Equal(expectedSOV.Weight, currentValidator.Weight) - require.Equal(expectedSOV.StartTime, currentValidator.StartTime) - require.Equal(expectedSOV.MinNonce, currentValidator.MinNonce) - require.Equal(expectedSOV.isActive(), currentValidator.IsActive) - require.True(currentValidator.IsSoV) + require.Equal(expectedL1Validator.ValidationID, currentValidator.ValidationID) + require.Equal(expectedL1Validator.NodeID, currentValidator.NodeID) + require.Equal(expectedL1Validator.PublicKey, currentValidator.PublicKey.Serialize()) + require.Equal(expectedL1Validator.Weight, currentValidator.Weight) + require.Equal(expectedL1Validator.StartTime, currentValidator.StartTime) + require.Equal(expectedL1Validator.MinNonce, currentValidator.MinNonce) + require.Equal(expectedL1Validator.isActive(), currentValidator.IsActive) + require.True(currentValidator.IsL1Validator) } } }) diff --git a/vms/platformvm/state/subnet_only_validator.go b/vms/platformvm/state/subnet_only_validator.go deleted file mode 100644 index d7c20a25ca20..000000000000 --- a/vms/platformvm/state/subnet_only_validator.go +++ /dev/null @@ -1,439 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package state - -import ( - "bytes" - "errors" - "fmt" - - "github.com/google/btree" - - "github.com/ava-labs/avalanchego/cache" - "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/iterator" - "github.com/ava-labs/avalanchego/utils/math" - "github.com/ava-labs/avalanchego/utils/maybe" - "github.com/ava-labs/avalanchego/vms/platformvm/block" -) - -var ( - _ btree.LessFunc[SubnetOnlyValidator] = SubnetOnlyValidator.Less - _ utils.Sortable[SubnetOnlyValidator] = SubnetOnlyValidator{} - - ErrMutatedSubnetOnlyValidator = errors.New("subnet-only validator contains mutated constant fields") - ErrConflictingSubnetOnlyValidator = errors.New("subnet-only validator contains conflicting subnetID + nodeID pair") - ErrDuplicateSubnetOnlyValidator = errors.New("subnet-only validator contains duplicate subnetID + nodeID pair") -) - -type SubnetOnlyValidators interface { - // GetActiveSubnetOnlyValidatorsIterator returns an iterator of all the - // active subnet-only validators in increasing order of EndAccumulatedFee. - // - // It is the caller's responsibility to call [Release] on the iterator after - // use. - // - // It is not guaranteed to be safe to modify the state while using the - // iterator. After releasing the iterator, the state may be safely modified. - GetActiveSubnetOnlyValidatorsIterator() (iterator.Iterator[SubnetOnlyValidator], error) - - // NumActiveSubnetOnlyValidators returns the number of currently active - // subnet-only validators. - NumActiveSubnetOnlyValidators() int - - // WeightOfSubnetOnlyValidators returns the total active and inactive weight - // of subnet-only validators on [subnetID]. - WeightOfSubnetOnlyValidators(subnetID ids.ID) (uint64, error) - - // GetSubnetOnlyValidator returns the validator with [validationID] if it - // exists. If the validator does not exist, [err] will equal - // [database.ErrNotFound]. - GetSubnetOnlyValidator(validationID ids.ID) (SubnetOnlyValidator, error) - - // HasSubnetOnlyValidator returns the validator with [validationID] if it - // exists. - HasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, error) - - // PutSubnetOnlyValidator inserts [sov] as a validator. If the weight of the - // validator is 0, the validator is removed. - // - // If inserting this validator attempts to modify any of the constant fields - // of the subnet-only validator struct, an error will be returned. - // - // If inserting this validator would cause the total weight of subnet-only - // validators on a subnet to overflow MaxUint64, an error will be returned. - // - // If inserting this validator would cause there to be multiple validators - // with the same subnetID and nodeID pair to exist at the same time, an - // error will be returned. - // - // If an SoV with the same validationID as a previously removed SoV is - // added, the behavior is undefined. - PutSubnetOnlyValidator(sov SubnetOnlyValidator) error -} - -// SubnetOnlyValidator defines an ACP-77 validator. For a given ValidationID, it -// is expected for SubnetID, NodeID, PublicKey, RemainingBalanceOwner, and -// StartTime to be constant. -type SubnetOnlyValidator struct { - // ValidationID is not serialized because it is used as the key in the - // database, so it doesn't need to be stored in the value. - ValidationID ids.ID - - SubnetID ids.ID `serialize:"true"` - NodeID ids.NodeID `serialize:"true"` - - // PublicKey is the uncompressed BLS public key of the validator. It is - // guaranteed to be populated. - PublicKey []byte `serialize:"true"` - - // RemainingBalanceOwner is the owner that will be used when returning the - // balance of the validator after removing accrued fees. - RemainingBalanceOwner []byte `serialize:"true"` - - // DeactivationOwner is the owner that can manually deactivate the - // validator. - DeactivationOwner []byte `serialize:"true"` - - // StartTime is the unix timestamp, in seconds, when this validator was - // added to the set. - StartTime uint64 `serialize:"true"` - - // Weight of this validator. It can be updated when the MinNonce is - // increased. If the weight is being set to 0, the validator is being - // removed. - Weight uint64 `serialize:"true"` - - // MinNonce is the smallest nonce that can be used to modify this - // validator's weight. It is initially set to 0 and is set to one higher - // than the last nonce used. It is not valid to use nonce MaxUint64 unless - // the weight is being set to 0, which removes the validator from the set. - MinNonce uint64 `serialize:"true"` - - // EndAccumulatedFee is the amount of accumulated fees per validator that - // can accrue before this validator must be deactivated. It is equal to the - // amount of fees this validator is willing to pay plus the total amount of - // fees a validator would have needed to pay from the activation of the Etna - // upgrade until this validator was registered. Note that this relies on the - // fact that every validator is charged the same fee for each unit of time. - // - // If this value is 0, the validator is inactive. - EndAccumulatedFee uint64 `serialize:"true"` -} - -func (v SubnetOnlyValidator) Less(o SubnetOnlyValidator) bool { - return v.Compare(o) == -1 -} - -// Compare determines a canonical ordering of SubnetOnlyValidators based on -// their EndAccumulatedFees and ValidationIDs. Lower EndAccumulatedFees result -// in an earlier ordering. -func (v SubnetOnlyValidator) Compare(o SubnetOnlyValidator) int { - switch { - case v.EndAccumulatedFee < o.EndAccumulatedFee: - return -1 - case o.EndAccumulatedFee < v.EndAccumulatedFee: - return 1 - default: - return v.ValidationID.Compare(o.ValidationID) - } -} - -// immutableFieldsAreUnmodified returns true if two versions of the same -// validator are valid. Either because the validationID has changed or because -// no unexpected fields have been modified. -func (v SubnetOnlyValidator) immutableFieldsAreUnmodified(o SubnetOnlyValidator) bool { - if v.ValidationID != o.ValidationID { - return true - } - return v.SubnetID == o.SubnetID && - v.NodeID == o.NodeID && - bytes.Equal(v.PublicKey, o.PublicKey) && - bytes.Equal(v.RemainingBalanceOwner, o.RemainingBalanceOwner) && - bytes.Equal(v.DeactivationOwner, o.DeactivationOwner) && - v.StartTime == o.StartTime -} - -func (v SubnetOnlyValidator) isDeleted() bool { - return v.Weight == 0 -} - -func (v SubnetOnlyValidator) isActive() bool { - return v.Weight != 0 && v.EndAccumulatedFee != 0 -} - -func (v SubnetOnlyValidator) effectiveValidationID() ids.ID { - if v.isActive() { - return v.ValidationID - } - return ids.Empty -} - -func (v SubnetOnlyValidator) effectiveNodeID() ids.NodeID { - if v.isActive() { - return v.NodeID - } - return ids.EmptyNodeID -} - -func (v SubnetOnlyValidator) effectivePublicKey() *bls.PublicKey { - if v.isActive() { - return bls.PublicKeyFromValidUncompressedBytes(v.PublicKey) - } - return nil -} - -func (v SubnetOnlyValidator) effectivePublicKeyBytes() []byte { - if v.isActive() { - return v.PublicKey - } - return nil -} - -func getSubnetOnlyValidator( - cache cache.Cacher[ids.ID, maybe.Maybe[SubnetOnlyValidator]], - db database.KeyValueReader, - validationID ids.ID, -) (SubnetOnlyValidator, error) { - if maybeSOV, ok := cache.Get(validationID); ok { - if maybeSOV.IsNothing() { - return SubnetOnlyValidator{}, database.ErrNotFound - } - return maybeSOV.Value(), nil - } - - bytes, err := db.Get(validationID[:]) - if err == database.ErrNotFound { - cache.Put(validationID, maybe.Nothing[SubnetOnlyValidator]()) - return SubnetOnlyValidator{}, database.ErrNotFound - } - if err != nil { - return SubnetOnlyValidator{}, err - } - - sov := SubnetOnlyValidator{ - ValidationID: validationID, - } - if _, err := block.GenesisCodec.Unmarshal(bytes, &sov); err != nil { - return SubnetOnlyValidator{}, fmt.Errorf("failed to unmarshal SubnetOnlyValidator: %w", err) - } - - cache.Put(validationID, maybe.Some(sov)) - return sov, nil -} - -func putSubnetOnlyValidator( - db database.KeyValueWriter, - cache cache.Cacher[ids.ID, maybe.Maybe[SubnetOnlyValidator]], - sov SubnetOnlyValidator, -) error { - bytes, err := block.GenesisCodec.Marshal(block.CodecVersion, sov) - if err != nil { - return fmt.Errorf("failed to marshal SubnetOnlyValidator: %w", err) - } - if err := db.Put(sov.ValidationID[:], bytes); err != nil { - return err - } - - cache.Put(sov.ValidationID, maybe.Some(sov)) - return nil -} - -func deleteSubnetOnlyValidator( - db database.KeyValueDeleter, - cache cache.Cacher[ids.ID, maybe.Maybe[SubnetOnlyValidator]], - validationID ids.ID, -) error { - if err := db.Delete(validationID[:]); err != nil { - return err - } - - cache.Put(validationID, maybe.Nothing[SubnetOnlyValidator]()) - return nil -} - -type subnetOnlyValidatorsDiff struct { - netAddedActive int // May be negative - modifiedTotalWeight map[ids.ID]uint64 // subnetID -> totalWeight - modified map[ids.ID]SubnetOnlyValidator - modifiedHasNodeIDs map[subnetIDNodeID]bool - active *btree.BTreeG[SubnetOnlyValidator] -} - -func newSubnetOnlyValidatorsDiff() *subnetOnlyValidatorsDiff { - return &subnetOnlyValidatorsDiff{ - modifiedTotalWeight: make(map[ids.ID]uint64), - modified: make(map[ids.ID]SubnetOnlyValidator), - modifiedHasNodeIDs: make(map[subnetIDNodeID]bool), - active: btree.NewG(defaultTreeDegree, SubnetOnlyValidator.Less), - } -} - -// getActiveSubnetOnlyValidatorsIterator takes in the parent iterator, removes -// all modified validators, and then adds all modified active validators. -func (d *subnetOnlyValidatorsDiff) getActiveSubnetOnlyValidatorsIterator(parentIterator iterator.Iterator[SubnetOnlyValidator]) iterator.Iterator[SubnetOnlyValidator] { - return iterator.Merge( - SubnetOnlyValidator.Less, - iterator.Filter(parentIterator, func(sov SubnetOnlyValidator) bool { - _, ok := d.modified[sov.ValidationID] - return ok - }), - iterator.FromTree(d.active), - ) -} - -func (d *subnetOnlyValidatorsDiff) hasSubnetOnlyValidator(subnetID ids.ID, nodeID ids.NodeID) (bool, bool) { - subnetIDNodeID := subnetIDNodeID{ - subnetID: subnetID, - nodeID: nodeID, - } - has, modified := d.modifiedHasNodeIDs[subnetIDNodeID] - return has, modified -} - -func (d *subnetOnlyValidatorsDiff) putSubnetOnlyValidator(state Chain, sov SubnetOnlyValidator) error { - var ( - prevWeight uint64 - prevActive bool - newActive = sov.isActive() - ) - switch priorSOV, err := state.GetSubnetOnlyValidator(sov.ValidationID); err { - case nil: - if !priorSOV.immutableFieldsAreUnmodified(sov) { - return ErrMutatedSubnetOnlyValidator - } - - prevWeight = priorSOV.Weight - prevActive = priorSOV.isActive() - case database.ErrNotFound: - // Verify that there is not a legacy subnet validator with the same - // subnetID+nodeID as this L1 validator. - _, err := state.GetCurrentValidator(sov.SubnetID, sov.NodeID) - if err == nil { - return ErrConflictingSubnetOnlyValidator - } - if err != database.ErrNotFound { - return err - } - - has, err := state.HasSubnetOnlyValidator(sov.SubnetID, sov.NodeID) - if err != nil { - return err - } - if has { - return ErrDuplicateSubnetOnlyValidator - } - default: - return err - } - - if prevWeight != sov.Weight { - weight, err := state.WeightOfSubnetOnlyValidators(sov.SubnetID) - if err != nil { - return err - } - - weight, err = math.Sub(weight, prevWeight) - if err != nil { - return err - } - weight, err = math.Add(weight, sov.Weight) - if err != nil { - return err - } - - d.modifiedTotalWeight[sov.SubnetID] = weight - } - - switch { - case prevActive && !newActive: - d.netAddedActive-- - case !prevActive && newActive: - d.netAddedActive++ - } - - if prevSOV, ok := d.modified[sov.ValidationID]; ok { - d.active.Delete(prevSOV) - } - d.modified[sov.ValidationID] = sov - - subnetIDNodeID := subnetIDNodeID{ - subnetID: sov.SubnetID, - nodeID: sov.NodeID, - } - d.modifiedHasNodeIDs[subnetIDNodeID] = !sov.isDeleted() - if sov.isActive() { - d.active.ReplaceOrInsert(sov) - } - return nil -} - -type activeSubnetOnlyValidators struct { - lookup map[ids.ID]SubnetOnlyValidator - tree *btree.BTreeG[SubnetOnlyValidator] -} - -func newActiveSubnetOnlyValidators() *activeSubnetOnlyValidators { - return &activeSubnetOnlyValidators{ - lookup: make(map[ids.ID]SubnetOnlyValidator), - tree: btree.NewG(defaultTreeDegree, SubnetOnlyValidator.Less), - } -} - -func (a *activeSubnetOnlyValidators) get(validationID ids.ID) (SubnetOnlyValidator, bool) { - sov, ok := a.lookup[validationID] - return sov, ok -} - -func (a *activeSubnetOnlyValidators) put(sov SubnetOnlyValidator) { - a.lookup[sov.ValidationID] = sov - a.tree.ReplaceOrInsert(sov) -} - -func (a *activeSubnetOnlyValidators) delete(validationID ids.ID) bool { - sov, ok := a.lookup[validationID] - if !ok { - return false - } - - delete(a.lookup, validationID) - a.tree.Delete(sov) - return true -} - -func (a *activeSubnetOnlyValidators) len() int { - return len(a.lookup) -} - -func (a *activeSubnetOnlyValidators) newIterator() iterator.Iterator[SubnetOnlyValidator] { - return iterator.FromTree(a.tree) -} - -func (a *activeSubnetOnlyValidators) addStakersToValidatorManager(vdrs validators.Manager) error { - for validationID, sov := range a.lookup { - pk := bls.PublicKeyFromValidUncompressedBytes(sov.PublicKey) - if err := vdrs.AddStaker(sov.SubnetID, sov.NodeID, pk, validationID, sov.Weight); err != nil { - return err - } - } - return nil -} - -func addSoVToValidatorManager(vdrs validators.Manager, sov SubnetOnlyValidator) error { - nodeID := sov.effectiveNodeID() - if vdrs.GetWeight(sov.SubnetID, nodeID) != 0 { - return vdrs.AddWeight(sov.SubnetID, nodeID, sov.Weight) - } - return vdrs.AddStaker( - sov.SubnetID, - nodeID, - sov.effectivePublicKey(), - sov.effectiveValidationID(), - sov.Weight, - ) -} diff --git a/vms/platformvm/state/subnet_only_validator_test.go b/vms/platformvm/state/subnet_only_validator_test.go deleted file mode 100644 index 3ffe080e0723..000000000000 --- a/vms/platformvm/state/subnet_only_validator_test.go +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package state - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/cache" - "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/memdb" - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/maybe" - "github.com/ava-labs/avalanchego/vms/platformvm/block" -) - -func TestSubnetOnlyValidator_Compare(t *testing.T) { - tests := []struct { - name string - v SubnetOnlyValidator - o SubnetOnlyValidator - expected int - }{ - { - name: "v.EndAccumulatedFee < o.EndAccumulatedFee", - v: SubnetOnlyValidator{ - ValidationID: ids.GenerateTestID(), - EndAccumulatedFee: 1, - }, - o: SubnetOnlyValidator{ - ValidationID: ids.GenerateTestID(), - EndAccumulatedFee: 2, - }, - expected: -1, - }, - { - name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID < o.ValidationID", - v: SubnetOnlyValidator{ - ValidationID: ids.ID{0}, - EndAccumulatedFee: 1, - }, - o: SubnetOnlyValidator{ - ValidationID: ids.ID{1}, - EndAccumulatedFee: 1, - }, - expected: -1, - }, - { - name: "v.EndAccumulatedFee = o.EndAccumulatedFee, v.ValidationID = o.ValidationID", - v: SubnetOnlyValidator{ - ValidationID: ids.ID{0}, - EndAccumulatedFee: 1, - }, - o: SubnetOnlyValidator{ - ValidationID: ids.ID{0}, - EndAccumulatedFee: 1, - }, - expected: 0, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require := require.New(t) - - require.Equal(test.expected, test.v.Compare(test.o)) - require.Equal(-test.expected, test.o.Compare(test.v)) - require.Equal(test.expected == -1, test.v.Less(test.o)) - require.False(test.o.Less(test.v)) - }) - } -} - -func TestSubnetOnlyValidator_immutableFieldsAreUnmodified(t *testing.T) { - var ( - randomizeSOV = func(sov SubnetOnlyValidator) SubnetOnlyValidator { - // Randomize unrelated fields - sov.Weight = rand.Uint64() // #nosec G404 - sov.MinNonce = rand.Uint64() // #nosec G404 - sov.EndAccumulatedFee = rand.Uint64() // #nosec G404 - return sov - } - sov = newSoV() - ) - - t.Run("equal", func(t *testing.T) { - v := randomizeSOV(sov) - require.True(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("everything is different", func(t *testing.T) { - v := randomizeSOV(newSoV()) - require.True(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different subnetID", func(t *testing.T) { - v := randomizeSOV(sov) - v.SubnetID = ids.GenerateTestID() - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different nodeID", func(t *testing.T) { - v := randomizeSOV(sov) - v.NodeID = ids.GenerateTestNodeID() - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different publicKey", func(t *testing.T) { - v := randomizeSOV(sov) - v.PublicKey = utils.RandomBytes(bls.PublicKeyLen) - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different remainingBalanceOwner", func(t *testing.T) { - v := randomizeSOV(sov) - v.RemainingBalanceOwner = utils.RandomBytes(32) - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different deactivationOwner", func(t *testing.T) { - v := randomizeSOV(sov) - v.DeactivationOwner = utils.RandomBytes(32) - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) - t.Run("different startTime", func(t *testing.T) { - v := randomizeSOV(sov) - v.StartTime = rand.Uint64() // #nosec G404 - require.False(t, sov.immutableFieldsAreUnmodified(v)) - }) -} - -func TestGetSubnetOnlyValidator(t *testing.T) { - var ( - sov = newSoV() - dbWithSoV = memdb.New() - dbWithoutSoV = memdb.New() - cacheWithSoV = &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10} - cacheWithoutSoV = &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10} - ) - - require.NoError(t, putSubnetOnlyValidator(dbWithSoV, cacheWithSoV, sov)) - require.NoError(t, deleteSubnetOnlyValidator(dbWithoutSoV, cacheWithoutSoV, sov.ValidationID)) - - tests := []struct { - name string - cache cache.Cacher[ids.ID, maybe.Maybe[SubnetOnlyValidator]] - db database.KeyValueReader - expectedSoV SubnetOnlyValidator - expectedErr error - expectedEntry maybe.Maybe[SubnetOnlyValidator] - }{ - { - name: "cached with validator", - cache: cacheWithSoV, - db: dbWithoutSoV, - expectedSoV: sov, - expectedEntry: maybe.Some(sov), - }, - { - name: "from disk with validator", - cache: &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10}, - db: dbWithSoV, - expectedSoV: sov, - expectedEntry: maybe.Some(sov), - }, - { - name: "cached without validator", - cache: cacheWithoutSoV, - db: dbWithSoV, - expectedErr: database.ErrNotFound, - }, - { - name: "from disk without validator", - cache: &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10}, - db: dbWithoutSoV, - expectedErr: database.ErrNotFound, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require := require.New(t) - - gotSoV, err := getSubnetOnlyValidator(test.cache, test.db, sov.ValidationID) - require.ErrorIs(err, test.expectedErr) - require.Equal(test.expectedSoV, gotSoV) - - cachedSoV, ok := test.cache.Get(sov.ValidationID) - require.True(ok) - require.Equal(test.expectedEntry, cachedSoV) - }) - } -} - -func TestPutSubnetOnlyValidator(t *testing.T) { - var ( - require = require.New(t) - sov = newSoV() - db = memdb.New() - cache = &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10} - ) - expectedSoVBytes, err := block.GenesisCodec.Marshal(block.CodecVersion, sov) - require.NoError(err) - - require.NoError(putSubnetOnlyValidator(db, cache, sov)) - - sovBytes, err := db.Get(sov.ValidationID[:]) - require.NoError(err) - require.Equal(expectedSoVBytes, sovBytes) - - sovFromCache, ok := cache.Get(sov.ValidationID) - require.True(ok) - require.Equal(maybe.Some(sov), sovFromCache) -} - -func TestDeleteSubnetOnlyValidator(t *testing.T) { - var ( - require = require.New(t) - validationID = ids.GenerateTestID() - db = memdb.New() - cache = &cache.LRU[ids.ID, maybe.Maybe[SubnetOnlyValidator]]{Size: 10} - ) - require.NoError(db.Put(validationID[:], nil)) - - require.NoError(deleteSubnetOnlyValidator(db, cache, validationID)) - - hasSoV, err := db.Has(validationID[:]) - require.NoError(err) - require.False(hasSoV) - - sovFromCache, ok := cache.Get(validationID) - require.True(ok) - require.Equal(maybe.Nothing[SubnetOnlyValidator](), sovFromCache) -} - -func newSoV() SubnetOnlyValidator { - return SubnetOnlyValidator{ - ValidationID: ids.GenerateTestID(), - SubnetID: ids.GenerateTestID(), - NodeID: ids.GenerateTestNodeID(), - PublicKey: utils.RandomBytes(bls.PublicKeyLen), - RemainingBalanceOwner: utils.RandomBytes(32), - DeactivationOwner: utils.RandomBytes(32), - StartTime: rand.Uint64(), // #nosec G404 - Weight: rand.Uint64(), // #nosec G404 - MinNonce: rand.Uint64(), // #nosec G404 - EndAccumulatedFee: rand.Uint64(), // #nosec G404 - } -} diff --git a/vms/platformvm/txs/codec.go b/vms/platformvm/txs/codec.go index e3b4539e91e2..9dacee7781c5 100644 --- a/vms/platformvm/txs/codec.go +++ b/vms/platformvm/txs/codec.go @@ -122,10 +122,10 @@ func RegisterDurangoTypes(targetCodec linearcodec.Codec) error { // were valid during the Etna series of upgrades. func RegisterEtnaTypes(targetCodec linearcodec.Codec) error { return errors.Join( - targetCodec.RegisterType(&ConvertSubnetTx{}), - targetCodec.RegisterType(&RegisterSubnetValidatorTx{}), - targetCodec.RegisterType(&SetSubnetValidatorWeightTx{}), - targetCodec.RegisterType(&IncreaseBalanceTx{}), - targetCodec.RegisterType(&DisableSubnetValidatorTx{}), + targetCodec.RegisterType(&ConvertSubnetToL1Tx{}), + targetCodec.RegisterType(&RegisterL1ValidatorTx{}), + targetCodec.RegisterType(&SetL1ValidatorWeightTx{}), + targetCodec.RegisterType(&IncreaseL1ValidatorBalanceTx{}), + targetCodec.RegisterType(&DisableL1ValidatorTx{}), ) } diff --git a/vms/platformvm/txs/convert_subnet_tx.go b/vms/platformvm/txs/convert_subnet_to_l1_tx.go similarity index 85% rename from vms/platformvm/txs/convert_subnet_tx.go rename to vms/platformvm/txs/convert_subnet_to_l1_tx.go index 7f76c962a207..821db3371833 100644 --- a/vms/platformvm/txs/convert_subnet_tx.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx.go @@ -21,8 +21,8 @@ import ( const MaxSubnetAddressLength = 4096 var ( - _ UnsignedTx = (*ConvertSubnetTx)(nil) - _ utils.Sortable[*ConvertSubnetValidator] = (*ConvertSubnetValidator)(nil) + _ UnsignedTx = (*ConvertSubnetToL1Tx)(nil) + _ utils.Sortable[*ConvertSubnetToL1Validator] = (*ConvertSubnetToL1Validator)(nil) ErrConvertPermissionlessSubnet = errors.New("cannot convert a permissionless subnet") ErrAddressTooLong = errors.New("address is too long") @@ -31,7 +31,7 @@ var ( ErrZeroWeight = errors.New("validator weight must be non-zero") ) -type ConvertSubnetTx struct { +type ConvertSubnetToL1Tx struct { // Metadata, inputs and outputs BaseTx `serialize:"true"` // ID of the Subnet to transform @@ -41,12 +41,12 @@ type ConvertSubnetTx struct { // Address of the Subnet manager Address types.JSONByteSlice `serialize:"true" json:"address"` // Initial pay-as-you-go validators for the Subnet - Validators []*ConvertSubnetValidator `serialize:"true" json:"validators"` + Validators []*ConvertSubnetToL1Validator `serialize:"true" json:"validators"` // Authorizes this conversion SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` } -func (tx *ConvertSubnetTx) SyntacticVerify(ctx *snow.Context) error { +func (tx *ConvertSubnetToL1Tx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: return ErrNilTx @@ -79,11 +79,11 @@ func (tx *ConvertSubnetTx) SyntacticVerify(ctx *snow.Context) error { return nil } -func (tx *ConvertSubnetTx) Visit(visitor Visitor) error { - return visitor.ConvertSubnetTx(tx) +func (tx *ConvertSubnetToL1Tx) Visit(visitor Visitor) error { + return visitor.ConvertSubnetToL1Tx(tx) } -type ConvertSubnetValidator struct { +type ConvertSubnetToL1Validator struct { // NodeID of this validator NodeID types.JSONByteSlice `serialize:"true" json:"nodeID"` // Weight of this validator used when sampling @@ -102,11 +102,11 @@ type ConvertSubnetValidator struct { DeactivationOwner message.PChainOwner `serialize:"true" json:"deactivationOwner"` } -func (v *ConvertSubnetValidator) Compare(o *ConvertSubnetValidator) int { +func (v *ConvertSubnetToL1Validator) Compare(o *ConvertSubnetToL1Validator) int { return bytes.Compare(v.NodeID, o.NodeID) } -func (v *ConvertSubnetValidator) Verify() error { +func (v *ConvertSubnetToL1Validator) Verify() error { if v.Weight == 0 { return ErrZeroWeight } diff --git a/vms/platformvm/txs/convert_subnet_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go similarity index 94% rename from vms/platformvm/txs/convert_subnet_tx_test.go rename to vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index d2e91acae0af..2fb59d249d67 100644 --- a/vms/platformvm/txs/convert_subnet_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -29,13 +29,13 @@ import ( ) var ( - //go:embed convert_subnet_tx_test_simple.json - convertSubnetTxSimpleJSON []byte - //go:embed convert_subnet_tx_test_complex.json - convertSubnetTxComplexJSON []byte + //go:embed convert_subnet_to_l1_tx_test_simple.json + convertSubnetToL1TxSimpleJSON []byte + //go:embed convert_subnet_to_l1_tx_test_complex.json + convertSubnetToL1TxComplexJSON []byte ) -func TestConvertSubnetTxSerialization(t *testing.T) { +func TestConvertSubnetToL1TxSerialization(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(t, err) sk, err := bls.SecretKeyFromBytes(skBytes) @@ -91,13 +91,13 @@ func TestConvertSubnetTxSerialization(t *testing.T) { tests := []struct { name string - tx *ConvertSubnetTx + tx *ConvertSubnetToL1Tx expectedBytes []byte expectedJSON []byte }{ { name: "simple", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -126,7 +126,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { Subnet: subnetID, ChainID: managerChainID, Address: managerAddress, - Validators: []*ConvertSubnetValidator{}, + Validators: []*ConvertSubnetToL1Validator{}, SubnetAuth: &secp256k1fx.Input{ SigIndices: []uint32{3}, }, @@ -134,7 +134,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { expectedBytes: []byte{ // Codec version 0x00, 0x00, - // ConvertSubnetTx Type ID + // ConvertSubnetToL1Tx Type ID 0x00, 0x00, 0x00, 0x23, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -195,11 +195,11 @@ func TestConvertSubnetTxSerialization(t *testing.T) { // index of signer 0x00, 0x00, 0x00, 0x03, }, - expectedJSON: convertSubnetTxSimpleJSON, + expectedJSON: convertSubnetToL1TxSimpleJSON, }, { name: "complex", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -296,7 +296,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { Subnet: subnetID, ChainID: managerChainID, Address: managerAddress, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: nodeID[:], Weight: 0x0102030405060708, @@ -323,7 +323,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { expectedBytes: []byte{ // Codec version 0x00, 0x00, - // ConvertSubnetTx Type ID + // ConvertSubnetToL1Tx Type ID 0x00, 0x00, 0x00, 0x23, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -523,7 +523,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { // number of signatures needed in authorization 0x00, 0x00, 0x00, 0x00, }, - expectedJSON: convertSubnetTxComplexJSON, + expectedJSON: convertSubnetToL1TxComplexJSON, }, } for _, test := range tests { @@ -549,7 +549,7 @@ func TestConvertSubnetTxSerialization(t *testing.T) { } } -func TestConvertSubnetTxSyntacticVerify(t *testing.T) { +func TestConvertSubnetToL1TxSyntacticVerify(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) @@ -563,7 +563,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { } validSubnetID = ids.GenerateTestID() invalidAddress = make(types.JSONByteSlice, MaxSubnetAddressLength+1) - validValidators = []*ConvertSubnetValidator{ + validValidators = []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: 1, @@ -581,7 +581,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { tests := []struct { name string - tx *ConvertSubnetTx + tx *ConvertSubnetToL1Tx expectedErr error }{ { @@ -593,7 +593,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { name: "already verified", // The tx includes invalid data to verify that a cached result is // returned. - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: BaseTx{ SyntacticallyVerified: true, }, @@ -606,7 +606,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid subnetID", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: constants.PrimaryNetworkID, Validators: validValidators, @@ -616,7 +616,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid address", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, Address: invalidAddress, @@ -627,7 +627,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid number of validators", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, Validators: nil, @@ -637,10 +637,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator order", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: []byte{ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -662,10 +662,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator weight", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: 0, @@ -680,10 +680,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator nodeID length", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen + 1), Weight: 1, @@ -698,10 +698,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator nodeID", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: ids.EmptyNodeID[:], Weight: 1, @@ -716,10 +716,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator pop", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: 1, @@ -734,10 +734,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator remaining balance owner", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: 1, @@ -754,10 +754,10 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid validator deactivation owner", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, - Validators: []*ConvertSubnetValidator{ + Validators: []*ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: 1, @@ -774,7 +774,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid BaseTx", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: BaseTx{}, Subnet: validSubnetID, Validators: validValidators, @@ -784,7 +784,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "invalid subnetAuth", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, Validators: validValidators, @@ -794,7 +794,7 @@ func TestConvertSubnetTxSyntacticVerify(t *testing.T) { }, { name: "passes verification", - tx: &ConvertSubnetTx{ + tx: &ConvertSubnetToL1Tx{ BaseTx: validBaseTx, Subnet: validSubnetID, Validators: validValidators, diff --git a/vms/platformvm/txs/convert_subnet_tx_test_complex.json b/vms/platformvm/txs/convert_subnet_to_l1_tx_test_complex.json similarity index 100% rename from vms/platformvm/txs/convert_subnet_tx_test_complex.json rename to vms/platformvm/txs/convert_subnet_to_l1_tx_test_complex.json diff --git a/vms/platformvm/txs/convert_subnet_tx_test_simple.json b/vms/platformvm/txs/convert_subnet_to_l1_tx_test_simple.json similarity index 100% rename from vms/platformvm/txs/convert_subnet_tx_test_simple.json rename to vms/platformvm/txs/convert_subnet_to_l1_tx_test_simple.json diff --git a/vms/platformvm/txs/disable_subnet_validator_tx.go b/vms/platformvm/txs/disable_l1_validator_tx.go similarity index 75% rename from vms/platformvm/txs/disable_subnet_validator_tx.go rename to vms/platformvm/txs/disable_l1_validator_tx.go index 08e59ed1fa56..c77e56b12120 100644 --- a/vms/platformvm/txs/disable_subnet_validator_tx.go +++ b/vms/platformvm/txs/disable_l1_validator_tx.go @@ -9,9 +9,9 @@ import ( "github.com/ava-labs/avalanchego/vms/components/verify" ) -var _ UnsignedTx = (*DisableSubnetValidatorTx)(nil) +var _ UnsignedTx = (*DisableL1ValidatorTx)(nil) -type DisableSubnetValidatorTx struct { +type DisableL1ValidatorTx struct { // Metadata, inputs and outputs BaseTx `serialize:"true"` // ID corresponding to the validator @@ -20,7 +20,7 @@ type DisableSubnetValidatorTx struct { DisableAuth verify.Verifiable `serialize:"true" json:"disableAuthorization"` } -func (tx *DisableSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error { +func (tx *DisableL1ValidatorTx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: return ErrNilTx @@ -40,6 +40,6 @@ func (tx *DisableSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error { return nil } -func (tx *DisableSubnetValidatorTx) Visit(visitor Visitor) error { - return visitor.DisableSubnetValidatorTx(tx) +func (tx *DisableL1ValidatorTx) Visit(visitor Visitor) error { + return visitor.DisableL1ValidatorTx(tx) } diff --git a/vms/platformvm/txs/disable_subnet_validator_tx_test.go b/vms/platformvm/txs/disable_l1_validator_tx_test.go similarity index 94% rename from vms/platformvm/txs/disable_subnet_validator_tx_test.go rename to vms/platformvm/txs/disable_l1_validator_tx_test.go index 425b522a4652..393140048b7e 100644 --- a/vms/platformvm/txs/disable_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/disable_l1_validator_tx_test.go @@ -23,10 +23,10 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -//go:embed disable_subnet_validator_tx_test.json -var disableSubnetValidatorTxJSON []byte +//go:embed disable_l1_validator_tx_test.json +var disableL1ValidatorTxJSON []byte -func TestDisableSubnetValidatorTxSerialization(t *testing.T) { +func TestDisableL1ValidatorTxSerialization(t *testing.T) { require := require.New(t) var ( @@ -61,7 +61,7 @@ func TestDisableSubnetValidatorTxSerialization(t *testing.T) { } ) - var unsignedTx UnsignedTx = &DisableSubnetValidatorTx{ + var unsignedTx UnsignedTx = &DisableL1ValidatorTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -166,7 +166,7 @@ func TestDisableSubnetValidatorTxSerialization(t *testing.T) { expectedBytes := []byte{ // Codec version 0x00, 0x00, - // DisableSubnetValidatorTx Type ID + // DisableL1ValidatorTx Type ID 0x00, 0x00, 0x00, 0x27, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -317,12 +317,12 @@ func TestDisableSubnetValidatorTxSerialization(t *testing.T) { require.NoError(err) require.Equal( // Normalize newlines for Windows - strings.ReplaceAll(string(disableSubnetValidatorTxJSON), "\r\n", "\n"), + strings.ReplaceAll(string(disableL1ValidatorTxJSON), "\r\n", "\n"), string(txJSON), ) } -func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { +func TestDisableL1ValidatorTxSyntacticVerify(t *testing.T) { var ( ctx = snowtest.Context(t, ids.GenerateTestID()) validBaseTx = BaseTx{ @@ -335,7 +335,7 @@ func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { ) tests := []struct { name string - tx *DisableSubnetValidatorTx + tx *DisableL1ValidatorTx expectedErr error }{ { @@ -347,7 +347,7 @@ func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { name: "already verified", // The tx includes invalid data to verify that a cached result is // returned. - tx: &DisableSubnetValidatorTx{ + tx: &DisableL1ValidatorTx{ BaseTx: BaseTx{ SyntacticallyVerified: true, }, @@ -356,7 +356,7 @@ func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { }, { name: "invalid BaseTx", - tx: &DisableSubnetValidatorTx{ + tx: &DisableL1ValidatorTx{ BaseTx: BaseTx{}, DisableAuth: validDisableAuth, }, @@ -364,7 +364,7 @@ func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { }, { name: "invalid disable auth", - tx: &DisableSubnetValidatorTx{ + tx: &DisableL1ValidatorTx{ BaseTx: validBaseTx, DisableAuth: &secp256k1fx.Input{ SigIndices: []uint32{1, 0}, @@ -374,7 +374,7 @@ func TestDisableSubnetValidatorTxSyntacticVerify(t *testing.T) { }, { name: "passes verification", - tx: &DisableSubnetValidatorTx{ + tx: &DisableL1ValidatorTx{ BaseTx: validBaseTx, DisableAuth: validDisableAuth, }, diff --git a/vms/platformvm/txs/disable_subnet_validator_tx_test.json b/vms/platformvm/txs/disable_l1_validator_tx_test.json similarity index 100% rename from vms/platformvm/txs/disable_subnet_validator_tx_test.json rename to vms/platformvm/txs/disable_l1_validator_tx_test.json diff --git a/vms/platformvm/txs/executor/atomic_tx_executor.go b/vms/platformvm/txs/executor/atomic_tx_executor.go index cfdf7f2112e1..c6f2030c7fcf 100644 --- a/vms/platformvm/txs/executor/atomic_tx_executor.go +++ b/vms/platformvm/txs/executor/atomic_tx_executor.go @@ -108,23 +108,23 @@ func (*atomicTxExecutor) BaseTx(*txs.BaseTx) error { return ErrWrongTxType } -func (*atomicTxExecutor) ConvertSubnetTx(*txs.ConvertSubnetTx) error { +func (*atomicTxExecutor) ConvertSubnetToL1Tx(*txs.ConvertSubnetToL1Tx) error { return ErrWrongTxType } -func (*atomicTxExecutor) RegisterSubnetValidatorTx(*txs.RegisterSubnetValidatorTx) error { +func (*atomicTxExecutor) RegisterL1ValidatorTx(*txs.RegisterL1ValidatorTx) error { return ErrWrongTxType } -func (*atomicTxExecutor) SetSubnetValidatorWeightTx(*txs.SetSubnetValidatorWeightTx) error { +func (*atomicTxExecutor) SetL1ValidatorWeightTx(*txs.SetL1ValidatorWeightTx) error { return ErrWrongTxType } -func (*atomicTxExecutor) IncreaseBalanceTx(*txs.IncreaseBalanceTx) error { +func (*atomicTxExecutor) IncreaseL1ValidatorBalanceTx(*txs.IncreaseL1ValidatorBalanceTx) error { return ErrWrongTxType } -func (*atomicTxExecutor) DisableSubnetValidatorTx(*txs.DisableSubnetValidatorTx) error { +func (*atomicTxExecutor) DisableL1ValidatorTx(*txs.DisableL1ValidatorTx) error { return ErrWrongTxType } diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index c930f7723e4e..33c7932fc3a8 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -282,9 +282,9 @@ func TestEtnaCreateChainTxInvalidWithManagedSubnet(t *testing.T) { builderDiff, err := state.NewDiffOn(stateDiff) require.NoError(err) - stateDiff.SetSubnetConversion( + stateDiff.SetSubnetToL1Conversion( subnetID, - state.SubnetConversion{ + state.SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: []byte("address"), diff --git a/vms/platformvm/txs/executor/proposal_tx_executor.go b/vms/platformvm/txs/executor/proposal_tx_executor.go index 75190e57cbc8..f7f965db70b3 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -127,23 +127,23 @@ func (*proposalTxExecutor) BaseTx(*txs.BaseTx) error { return ErrWrongTxType } -func (*proposalTxExecutor) ConvertSubnetTx(*txs.ConvertSubnetTx) error { +func (*proposalTxExecutor) ConvertSubnetToL1Tx(*txs.ConvertSubnetToL1Tx) error { return ErrWrongTxType } -func (*proposalTxExecutor) RegisterSubnetValidatorTx(*txs.RegisterSubnetValidatorTx) error { +func (*proposalTxExecutor) RegisterL1ValidatorTx(*txs.RegisterL1ValidatorTx) error { return ErrWrongTxType } -func (*proposalTxExecutor) SetSubnetValidatorWeightTx(*txs.SetSubnetValidatorWeightTx) error { +func (*proposalTxExecutor) SetL1ValidatorWeightTx(*txs.SetL1ValidatorWeightTx) error { return ErrWrongTxType } -func (*proposalTxExecutor) IncreaseBalanceTx(*txs.IncreaseBalanceTx) error { +func (*proposalTxExecutor) IncreaseL1ValidatorBalanceTx(*txs.IncreaseL1ValidatorBalanceTx) error { return ErrWrongTxType } -func (*proposalTxExecutor) DisableSubnetValidatorTx(*txs.DisableSubnetValidatorTx) error { +func (*proposalTxExecutor) DisableL1ValidatorTx(*txs.DisableL1ValidatorTx) error { return ErrWrongTxType } diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 5af4c6b1d355..07c93a33127a 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -34,32 +34,32 @@ import ( // TODO: Before Etna, ensure that the maximum number of expiries to track is // limited to a reasonable number by this window. const ( - second = 1 - minute = 60 * second - hour = 60 * minute - day = 24 * hour - RegisterSubnetValidatorTxExpiryWindow = day + second = 1 + minute = 60 * second + hour = 60 * minute + day = 24 * hour + RegisterL1ValidatorTxExpiryWindow = day ) var ( _ txs.Visitor = (*standardTxExecutor)(nil) - errEmptyNodeID = errors.New("validator nodeID cannot be empty") - errMaxStakeDurationTooLarge = errors.New("max stake duration must be less than or equal to the global max stake duration") - errMissingStartTimePreDurango = errors.New("staker transactions must have a StartTime pre-Durango") - errEtnaUpgradeNotActive = errors.New("attempting to use an Etna-upgrade feature prior to activation") - errTransformSubnetTxPostEtna = errors.New("TransformSubnetTx is not permitted post-Etna") - errMaxNumActiveValidators = errors.New("already at the max number of active validators") - errCouldNotLoadSubnetConversion = errors.New("could not load subnet conversion") - errWrongWarpMessageSourceChainID = errors.New("wrong warp message source chain ID") - errWrongWarpMessageSourceAddress = errors.New("wrong warp message source address") - errWarpMessageExpired = errors.New("warp message expired") - errWarpMessageNotYetAllowed = errors.New("warp message not yet allowed") - errWarpMessageAlreadyIssued = errors.New("warp message already issued") - errCouldNotLoadSoV = errors.New("could not load SoV") - errWarpMessageContainsStaleNonce = errors.New("warp message contains stale nonce") - errRemovingLastValidator = errors.New("attempting to remove the last SoV from a converted subnet") - errStateCorruption = errors.New("state corruption") + errEmptyNodeID = errors.New("validator nodeID cannot be empty") + errMaxStakeDurationTooLarge = errors.New("max stake duration must be less than or equal to the global max stake duration") + errMissingStartTimePreDurango = errors.New("staker transactions must have a StartTime pre-Durango") + errEtnaUpgradeNotActive = errors.New("attempting to use an Etna-upgrade feature prior to activation") + errTransformSubnetTxPostEtna = errors.New("TransformSubnetTx is not permitted post-Etna") + errMaxNumActiveValidators = errors.New("already at the max number of active validators") + errCouldNotLoadSubnetToL1Conversion = errors.New("could not load subnet conversion") + errWrongWarpMessageSourceChainID = errors.New("wrong warp message source chain ID") + errWrongWarpMessageSourceAddress = errors.New("wrong warp message source address") + errWarpMessageExpired = errors.New("warp message expired") + errWarpMessageNotYetAllowed = errors.New("warp message not yet allowed") + errWarpMessageAlreadyIssued = errors.New("warp message already issued") + errCouldNotLoadL1Validator = errors.New("could not load L1 validator") + errWarpMessageContainsStaleNonce = errors.New("warp message contains stale nonce") + errRemovingLastValidator = errors.New("attempting to remove the last L1 validator from a converted subnet") + errStateCorruption = errors.New("state corruption") ) // StandardTx executes the standard transaction [tx]. @@ -677,7 +677,7 @@ func (e *standardTxExecutor) BaseTx(tx *txs.BaseTx) error { return nil } -func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { +func (e *standardTxExecutor) ConvertSubnetToL1Tx(tx *txs.ConvertSubnetToL1Tx) error { var ( currentTimestamp = e.state.GetTimestamp() upgrades = e.backend.Config.UpgradeConfig @@ -706,13 +706,13 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { } var ( - startTime = uint64(currentTimestamp.Unix()) - currentFees = e.state.GetAccruedFees() - subnetConversionData = message.SubnetConversionData{ + startTime = uint64(currentTimestamp.Unix()) + currentFees = e.state.GetAccruedFees() + subnetToL1ConversionData = message.SubnetToL1ConversionData{ SubnetID: tx.Subnet, ManagerChainID: tx.ChainID, ManagerAddress: tx.Address, - Validators: make([]message.SubnetConversionValidatorData, len(tx.Validators)), + Validators: make([]message.SubnetToL1ConverstionValidatorData, len(tx.Validators)), } ) for i, vdr := range tx.Validators { @@ -730,7 +730,7 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return err } - sov := state.SubnetOnlyValidator{ + l1Validator := state.L1Validator{ ValidationID: tx.Subnet.Append(uint32(i)), SubnetID: tx.Subnet, NodeID: nodeID, @@ -744,11 +744,11 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { } if vdr.Balance != 0 { // We are attempting to add an active validator - if gas.Gas(e.state.NumActiveSubnetOnlyValidators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { + if gas.Gas(e.state.NumActiveL1Validators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { return errMaxNumActiveValidators } - sov.EndAccumulatedFee, err = math.Add(vdr.Balance, currentFees) + l1Validator.EndAccumulatedFee, err = math.Add(vdr.Balance, currentFees) if err != nil { return err } @@ -759,11 +759,11 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { } } - if err := e.state.PutSubnetOnlyValidator(sov); err != nil { + if err := e.state.PutL1Validator(l1Validator); err != nil { return err } - subnetConversionData.Validators[i] = message.SubnetConversionValidatorData{ + subnetToL1ConversionData.Validators[i] = message.SubnetToL1ConverstionValidatorData{ NodeID: vdr.NodeID, BLSPublicKey: vdr.Signer.PublicKey, Weight: vdr.Weight, @@ -782,7 +782,7 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return err } - conversionID, err := message.SubnetConversionID(subnetConversionData) + conversionID, err := message.SubnetToL1ConversionID(subnetToL1ConversionData) if err != nil { return err } @@ -794,9 +794,9 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { // Produce the UTXOS avax.Produce(e.state, txID, tx.Outs) // Track the subnet conversion in the database - e.state.SetSubnetConversion( + e.state.SetSubnetToL1Conversion( tx.Subnet, - state.SubnetConversion{ + state.SubnetToL1Conversion{ ConversionID: conversionID, ChainID: tx.ChainID, Addr: tx.Address, @@ -805,7 +805,7 @@ func (e *standardTxExecutor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return nil } -func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) error { +func (e *standardTxExecutor) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error { var ( currentTimestamp = e.state.GetTimestamp() upgrades = e.backend.Config.UpgradeConfig @@ -854,7 +854,7 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal if err != nil { return err } - msg, err := message.ParseRegisterSubnetValidator(addressedCall.Payload) + msg, err := message.ParseRegisterL1Validator(addressedCall.Payload) if err != nil { return err } @@ -873,8 +873,8 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal if msg.Expiry <= currentTimestampUnix { return fmt.Errorf("%w at %d and it is currently %d", errWarpMessageExpired, msg.Expiry, currentTimestampUnix) } - if secondsUntilExpiry := msg.Expiry - currentTimestampUnix; secondsUntilExpiry > RegisterSubnetValidatorTxExpiryWindow { - return fmt.Errorf("%w because time is %d seconds in the future but the limit is %d", errWarpMessageNotYetAllowed, secondsUntilExpiry, RegisterSubnetValidatorTxExpiryWindow) + if secondsUntilExpiry := msg.Expiry - currentTimestampUnix; secondsUntilExpiry > RegisterL1ValidatorTxExpiryWindow { + return fmt.Errorf("%w because time is %d seconds in the future but the limit is %d", errWarpMessageNotYetAllowed, secondsUntilExpiry, RegisterL1ValidatorTxExpiryWindow) } // Verify that this warp message isn't being replayed. @@ -901,7 +901,7 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal return err } - // Create the SoV. + // Create the L1 validator. nodeID, err := ids.ToNodeID(msg.NodeID) if err != nil { return err @@ -914,7 +914,7 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal if err != nil { return err } - sov := state.SubnetOnlyValidator{ + l1Validator := state.L1Validator{ ValidationID: validationID, SubnetID: msg.SubnetID, NodeID: nodeID, @@ -930,19 +930,19 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal // If the balance is non-zero, this validator should be initially active. if tx.Balance != 0 { // Verify that there is space for an active validator. - if gas.Gas(e.state.NumActiveSubnetOnlyValidators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { + if gas.Gas(e.state.NumActiveL1Validators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { return errMaxNumActiveValidators } // Mark the validator as active. currentFees := e.state.GetAccruedFees() - sov.EndAccumulatedFee, err = math.Add(tx.Balance, currentFees) + l1Validator.EndAccumulatedFee, err = math.Add(tx.Balance, currentFees) if err != nil { return err } } - if err := e.state.PutSubnetOnlyValidator(sov); err != nil { + if err := e.state.PutL1Validator(l1Validator); err != nil { return err } @@ -957,7 +957,7 @@ func (e *standardTxExecutor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVal return nil } -func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) error { +func (e *standardTxExecutor) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error { var ( currentTimestamp = e.state.GetTimestamp() upgrades = e.backend.Config.UpgradeConfig @@ -1002,7 +1002,7 @@ func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidat if err != nil { return err } - msg, err := message.ParseSubnetValidatorWeight(addressedCall.Payload) + msg, err := message.ParseL1ValidatorWeight(addressedCall.Payload) if err != nil { return err } @@ -1011,17 +1011,17 @@ func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidat } // Verify that the message contains a valid nonce for a current validator. - sov, err := e.state.GetSubnetOnlyValidator(msg.ValidationID) + l1Validator, err := e.state.GetL1Validator(msg.ValidationID) if err != nil { - return fmt.Errorf("%w: %w", errCouldNotLoadSoV, err) + return fmt.Errorf("%w: %w", errCouldNotLoadL1Validator, err) } - if msg.Nonce < sov.MinNonce { - return fmt.Errorf("%w %d must be at least %d", errWarpMessageContainsStaleNonce, msg.Nonce, sov.MinNonce) + if msg.Nonce < l1Validator.MinNonce { + return fmt.Errorf("%w %d must be at least %d", errWarpMessageContainsStaleNonce, msg.Nonce, l1Validator.MinNonce) } // Verify that the warp message was sent from the expected chain and // address. - if err := verifyL1Conversion(e.state, sov.SubnetID, warpMessage.SourceChainID, addressedCall.SourceAddress); err != nil { + if err := verifyL1Conversion(e.state, l1Validator.SubnetID, warpMessage.SourceChainID, addressedCall.SourceAddress); err != nil { return err } @@ -1030,30 +1030,30 @@ func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidat // Check if we are removing the validator. if msg.Weight == 0 { // Verify that we are not removing the last validator. - weight, err := e.state.WeightOfSubnetOnlyValidators(sov.SubnetID) + weight, err := e.state.WeightOfL1Validators(l1Validator.SubnetID) if err != nil { - return fmt.Errorf("could not load SoV weights: %w", err) + return fmt.Errorf("could not load L1 validator weights: %w", err) } - if weight == sov.Weight { + if weight == l1Validator.Weight { return errRemovingLastValidator } // If the validator is currently active, we need to refund the remaining // balance. - if sov.EndAccumulatedFee != 0 { + if l1Validator.EndAccumulatedFee != 0 { var remainingBalanceOwner message.PChainOwner - if _, err := txs.Codec.Unmarshal(sov.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { + if _, err := txs.Codec.Unmarshal(l1Validator.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { return fmt.Errorf("%w: remaining balance owner is malformed", errStateCorruption) } accruedFees := e.state.GetAccruedFees() - if sov.EndAccumulatedFee <= accruedFees { + if l1Validator.EndAccumulatedFee <= accruedFees { // This check should be unreachable. However, it prevents AVAX // from being minted due to state corruption. This also prevents // invalid UTXOs from being created (with 0 value). return fmt.Errorf("%w: validator should have already been disabled", errStateCorruption) } - remainingBalance := sov.EndAccumulatedFee - accruedFees + remainingBalance := l1Validator.EndAccumulatedFee - accruedFees utxo := &avax.UTXO{ UTXOID: avax.UTXOID{ @@ -1080,9 +1080,9 @@ func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidat // doesn't matter. If weight is not 0, [msg.Nonce] is enforced by // [msg.Verify()] to be less than MaxUInt64 and can therefore be incremented // without overflow. - sov.MinNonce = msg.Nonce + 1 - sov.Weight = msg.Weight - if err := e.state.PutSubnetOnlyValidator(sov); err != nil { + l1Validator.MinNonce = msg.Nonce + 1 + l1Validator.Weight = msg.Weight + if err := e.state.PutL1Validator(l1Validator); err != nil { return err } @@ -1093,7 +1093,7 @@ func (e *standardTxExecutor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidat return nil } -func (e *standardTxExecutor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error { +func (e *standardTxExecutor) IncreaseL1ValidatorBalanceTx(tx *txs.IncreaseL1ValidatorBalanceTx) error { var ( currentTimestamp = e.state.GetTimestamp() upgrades = e.backend.Config.UpgradeConfig @@ -1134,25 +1134,25 @@ func (e *standardTxExecutor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error return err } - sov, err := e.state.GetSubnetOnlyValidator(tx.ValidationID) + l1Validator, err := e.state.GetL1Validator(tx.ValidationID) if err != nil { return err } // If the validator is currently inactive, we are activating it. - if sov.EndAccumulatedFee == 0 { - if gas.Gas(e.state.NumActiveSubnetOnlyValidators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { + if l1Validator.EndAccumulatedFee == 0 { + if gas.Gas(e.state.NumActiveL1Validators()) >= e.backend.Config.ValidatorFeeConfig.Capacity { return errMaxNumActiveValidators } - sov.EndAccumulatedFee = e.state.GetAccruedFees() + l1Validator.EndAccumulatedFee = e.state.GetAccruedFees() } - sov.EndAccumulatedFee, err = math.Add(sov.EndAccumulatedFee, tx.Balance) + l1Validator.EndAccumulatedFee, err = math.Add(l1Validator.EndAccumulatedFee, tx.Balance) if err != nil { return err } - if err := e.state.PutSubnetOnlyValidator(sov); err != nil { + if err := e.state.PutL1Validator(l1Validator); err != nil { return err } @@ -1165,7 +1165,7 @@ func (e *standardTxExecutor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error return nil } -func (e *standardTxExecutor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValidatorTx) error { +func (e *standardTxExecutor) DisableL1ValidatorTx(tx *txs.DisableL1ValidatorTx) error { var ( currentTimestamp = e.state.GetTimestamp() upgrades = e.backend.Config.UpgradeConfig @@ -1182,13 +1182,13 @@ func (e *standardTxExecutor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValid return err } - sov, err := e.state.GetSubnetOnlyValidator(tx.ValidationID) + l1Validator, err := e.state.GetL1Validator(tx.ValidationID) if err != nil { - return fmt.Errorf("%w: %w", errCouldNotLoadSoV, err) + return fmt.Errorf("%w: %w", errCouldNotLoadL1Validator, err) } var disableOwner message.PChainOwner - if _, err := txs.Codec.Unmarshal(sov.DeactivationOwner, &disableOwner); err != nil { + if _, err := txs.Codec.Unmarshal(l1Validator.DeactivationOwner, &disableOwner); err != nil { return err } @@ -1232,23 +1232,23 @@ func (e *standardTxExecutor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValid avax.Produce(e.state, txID, tx.Outs) // If the validator is already disabled, there is nothing to do. - if sov.EndAccumulatedFee == 0 { + if l1Validator.EndAccumulatedFee == 0 { return nil } var remainingBalanceOwner message.PChainOwner - if _, err := txs.Codec.Unmarshal(sov.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { + if _, err := txs.Codec.Unmarshal(l1Validator.RemainingBalanceOwner, &remainingBalanceOwner); err != nil { return err } accruedFees := e.state.GetAccruedFees() - if sov.EndAccumulatedFee <= accruedFees { + if l1Validator.EndAccumulatedFee <= accruedFees { // This check should be unreachable. However, including it ensures // that AVAX can't get minted out of thin air due to state // corruption. return fmt.Errorf("%w: validator should have already been disabled", errStateCorruption) } - remainingBalance := sov.EndAccumulatedFee - accruedFees + remainingBalance := l1Validator.EndAccumulatedFee - accruedFees utxo := &avax.UTXO{ UTXOID: avax.UTXOID{ @@ -1269,8 +1269,8 @@ func (e *standardTxExecutor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValid e.state.AddUTXO(utxo) // Disable the validator - sov.EndAccumulatedFee = 0 - return e.state.PutSubnetOnlyValidator(sov) + l1Validator.EndAccumulatedFee = 0 + return e.state.PutL1Validator(l1Validator) } // Creates the staker as defined in [stakerTx] and adds it to [e.State]. @@ -1353,15 +1353,15 @@ func verifyL1Conversion( expectedChainID ids.ID, expectedAddress []byte, ) error { - subnetConversion, err := state.GetSubnetConversion(subnetID) + subnetToL1Conversion, err := state.GetSubnetToL1Conversion(subnetID) if err != nil { - return fmt.Errorf("%w for %s with: %w", errCouldNotLoadSubnetConversion, subnetID, err) + return fmt.Errorf("%w for %s with: %w", errCouldNotLoadSubnetToL1Conversion, subnetID, err) } - if expectedChainID != subnetConversion.ChainID { - return fmt.Errorf("%w expected %s but had %s", errWrongWarpMessageSourceChainID, subnetConversion.ChainID, expectedChainID) + if expectedChainID != subnetToL1Conversion.ChainID { + return fmt.Errorf("%w expected %s but had %s", errWrongWarpMessageSourceChainID, subnetToL1Conversion.ChainID, expectedChainID) } - if !bytes.Equal(expectedAddress, subnetConversion.Addr) { - return fmt.Errorf("%w expected 0x%x but got 0x%x", errWrongWarpMessageSourceAddress, subnetConversion.Addr, expectedAddress) + if !bytes.Equal(expectedAddress, subnetToL1Conversion.Addr) { + return fmt.Errorf("%w expected 0x%x but got 0x%x", errWrongWarpMessageSourceAddress, subnetToL1Conversion.Addr, expectedAddress) } return nil } diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 793121a44917..7c1d49eeff22 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -909,9 +909,9 @@ func TestEtnaStandardTxExecutorAddSubnetValidator(t *testing.T) { onAcceptState, err := state.NewDiff(lastAcceptedID, env) require.NoError(err) - onAcceptState.SetSubnetConversion( + onAcceptState.SetSubnetToL1Conversion( subnetID, - state.SubnetConversion{ + state.SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: []byte("address"), @@ -1753,8 +1753,8 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { // This isn't actually called, but is added here as a regression // test to ensure that converted subnets can still remove // permissioned validators. - env.state.EXPECT().GetSubnetConversion(env.unsignedTx.Subnet).Return( - state.SubnetConversion{ + env.state.EXPECT().GetSubnetToL1Conversion(env.unsignedTx.Subnet).Return( + state.SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: []byte("address"), @@ -2226,8 +2226,8 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil) - env.state.EXPECT().GetSubnetConversion(env.unsignedTx.Subnet).Return( - state.SubnetConversion{}, + env.state.EXPECT().GetSubnetToL1Conversion(env.unsignedTx.Subnet).Return( + state.SubnetToL1Conversion{}, database.ErrNotFound, ).Times(1) env.state.EXPECT().GetSubnetTransformation(env.unsignedTx.Subnet).Return(nil, database.ErrNotFound).Times(1) @@ -2267,8 +2267,8 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil).Times(1) - env.state.EXPECT().GetSubnetConversion(env.unsignedTx.Subnet).Return( - state.SubnetConversion{ + env.state.EXPECT().GetSubnetToL1Conversion(env.unsignedTx.Subnet).Return( + state.SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: make([]byte, 20), @@ -2308,8 +2308,8 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { subnetOwner := fxmock.NewOwner(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime).AnyTimes() env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(subnetOwner, nil).Times(1) - env.state.EXPECT().GetSubnetConversion(env.unsignedTx.Subnet).Return( - state.SubnetConversion{}, + env.state.EXPECT().GetSubnetToL1Conversion(env.unsignedTx.Subnet).Return( + state.SubnetToL1Conversion{}, database.ErrNotFound, ).Times(1) env.state.EXPECT().GetSubnetTransformation(env.unsignedTx.Subnet).Return(nil, database.ErrNotFound).Times(1) @@ -2357,7 +2357,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { } } -func TestStandardExecutorConvertSubnetTx(t *testing.T) { +func TestStandardExecutorConvertSubnetToL1Tx(t *testing.T) { var ( fx = &secp256k1fx.Fx{} vm = &secp256k1fx.TestVM{ @@ -2479,9 +2479,9 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { { name: "invalid if subnet is converted", updateExecutor: func(e *standardTxExecutor) error { - e.state.SetSubnetConversion( + e.state.SetSubnetToL1Conversion( subnetID, - state.SubnetConversion{ + state.SubnetToL1Conversion{ ConversionID: ids.GenerateTestID(), ChainID: ids.GenerateTestID(), Addr: utils.RandomBytes(32), @@ -2517,16 +2517,16 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { expectedErr: errMaxNumActiveValidators, }, { - name: "invalid subnet only validator", + name: "invalid L1 validator", updateExecutor: func(e *standardTxExecutor) error { - return e.state.PutSubnetOnlyValidator(state.SubnetOnlyValidator{ + return e.state.PutL1Validator(state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: subnetID, NodeID: nodeID, Weight: 1, }) }, - expectedErr: state.ErrDuplicateSubnetOnlyValidator, + expectedErr: state.ErrDuplicateL1Validator, }, { name: "insufficient fee", @@ -2550,7 +2550,7 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(err) - // Create the ConvertSubnetTx + // Create the ConvertSubnetToL1Tx const ( weight = 1 balance = 1 @@ -2569,7 +2569,7 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { chainID = ids.GenerateTestID() address = utils.RandomBytes(32) pop = signer.NewProofOfPossession(sk) - validator = &txs.ConvertSubnetValidator{ + validator = &txs.ConvertSubnetToL1Validator{ NodeID: nodeID.Bytes(), Weight: weight, Balance: balance, @@ -2578,11 +2578,11 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { DeactivationOwner: message.PChainOwner{}, } ) - convertSubnetTx, err := wallet.IssueConvertSubnetTx( + convertSubnetToL1Tx, err := wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ validator, }, test.builderOptions..., @@ -2601,36 +2601,36 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { Ctx: ctx, }, feeCalculator: state.PickFeeCalculator(defaultConfig, baseState), - tx: convertSubnetTx, + tx: convertSubnetToL1Tx, state: diff, } if test.updateExecutor != nil { require.NoError(test.updateExecutor(executor)) } - err = convertSubnetTx.Unsigned.Visit(executor) + err = convertSubnetToL1Tx.Unsigned.Visit(executor) require.ErrorIs(err, test.expectedErr) if err != nil { return } - for utxoID := range convertSubnetTx.InputIDs() { + for utxoID := range convertSubnetToL1Tx.InputIDs() { _, err := diff.GetUTXO(utxoID) require.ErrorIs(err, database.ErrNotFound) } - for _, expectedUTXO := range convertSubnetTx.UTXOs() { + for _, expectedUTXO := range convertSubnetToL1Tx.UTXOs() { utxoID := expectedUTXO.InputID() utxo, err := diff.GetUTXO(utxoID) require.NoError(err) require.Equal(expectedUTXO, utxo) } - expectedConversionID, err := message.SubnetConversionID(message.SubnetConversionData{ + expectedConversionID, err := message.SubnetToL1ConversionID(message.SubnetToL1ConversionData{ SubnetID: subnetID, ManagerChainID: chainID, ManagerAddress: address, - Validators: []message.SubnetConversionValidatorData{ + Validators: []message.SubnetToL1ConverstionValidatorData{ { NodeID: nodeID.Bytes(), BLSPublicKey: pop.PublicKey, @@ -2640,10 +2640,10 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { }) require.NoError(err) - stateConversion, err := diff.GetSubnetConversion(subnetID) + stateConversion, err := diff.GetSubnetToL1Conversion(subnetID) require.NoError(err) require.Equal( - state.SubnetConversion{ + state.SubnetToL1Conversion{ ConversionID: expectedConversionID, ChainID: chainID, Addr: address, @@ -2661,10 +2661,10 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { deactivationOwner, err := txs.Codec.Marshal(txs.CodecVersion, &validator.DeactivationOwner) require.NoError(err) - sov, err := diff.GetSubnetOnlyValidator(validationID) + l1Validator, err := diff.GetL1Validator(validationID) require.NoError(err) require.Equal( - state.SubnetOnlyValidator{ + state.L1Validator{ ValidationID: validationID, SubnetID: subnetID, NodeID: nodeID, @@ -2676,13 +2676,13 @@ func TestStandardExecutorConvertSubnetTx(t *testing.T) { MinNonce: 0, EndAccumulatedFee: validator.Balance + diff.GetAccruedFees(), }, - sov, + l1Validator, ) }) } } -func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { +func TestStandardExecutorRegisterL1ValidatorTx(t *testing.T) { var ( fx = &secp256k1fx.Fx{} vm = &secp256k1fx.TestVM{ @@ -2761,7 +2761,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { address = utils.RandomBytes(32) initialNodeID = ids.GenerateTestNodeID() initialPoP = signer.NewProofOfPossession(initialSK) - validator = &txs.ConvertSubnetValidator{ + validator = &txs.ConvertSubnetToL1Validator{ NodeID: initialNodeID.Bytes(), Weight: initialWeight, Balance: initialBalance, @@ -2770,11 +2770,11 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { DeactivationOwner: message.PChainOwner{}, } ) - convertSubnetTx, err := wallet.IssueConvertSubnetTx( + convertSubnetToL1Tx, err := wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ validator, }, ) @@ -2784,7 +2784,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { _, _, _, err = StandardTx( backend, feeCalculator, - convertSubnetTx, + convertSubnetToL1Tx, diff, ) require.NoError(t, err) @@ -2815,7 +2815,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { deactivationOwnerBytes, err := txs.Codec.Marshal(txs.CodecVersion, &deactivationOwner) require.NoError(t, err) - addressedCallPayload := must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + addressedCallPayload := must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( subnetID, nodeID, pop.PublicKey, @@ -2852,7 +2852,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { balance uint64 message []byte builderOptions []common.Option - updateTx func(*txs.RegisterSubnetValidatorTx) + updateTx func(*txs.RegisterL1ValidatorTx) updateExecutor func(*standardTxExecutor) error expectedErr error }{ @@ -2891,7 +2891,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { }, { name: "fee calculation overflow", - updateTx: func(tx *txs.RegisterSubnetValidatorTx) { + updateTx: func(tx *txs.RegisterL1ValidatorTx) { tx.Balance = math.MaxUint64 }, expectedErr: safemath.ErrOverflow, @@ -2932,7 +2932,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetConversion](t)(message.NewSubnetConversion(ids.Empty)).Bytes(), + must[*message.SubnetToL1Conversion](t)(message.NewSubnetToL1Conversion(ids.Empty)).Bytes(), )).Bytes(), )), warpSignature, @@ -2947,7 +2947,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( subnetID, nodeID, pop.PublicKey, @@ -2970,7 +2970,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( ids.GenerateTestID(), // invalid subnetID nodeID, pop.PublicKey, @@ -2983,12 +2983,12 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { )), warpSignature, )).Bytes(), - expectedErr: errCouldNotLoadSubnetConversion, + expectedErr: errCouldNotLoadSubnetToL1Conversion, }, { name: "invalid source chain", updateExecutor: func(e *standardTxExecutor) error { - e.state.SetSubnetConversion(subnetID, state.SubnetConversion{}) + e.state.SetSubnetToL1Conversion(subnetID, state.SubnetToL1Conversion{}) return nil }, expectedErr: errWrongWarpMessageSourceChainID, @@ -2996,7 +2996,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { { name: "invalid source address", updateExecutor: func(e *standardTxExecutor) error { - e.state.SetSubnetConversion(subnetID, state.SubnetConversion{ + e.state.SetSubnetToL1Conversion(subnetID, state.SubnetToL1Conversion{ ChainID: chainID, }) return nil @@ -3019,7 +3019,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( subnetID, nodeID, pop.PublicKey, @@ -3035,7 +3035,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { expectedErr: errWarpMessageNotYetAllowed, }, { - name: "SoV previously registered", + name: "L1 Validator previously registered", balance: 1, updateExecutor: func(e *standardTxExecutor) error { e.state.PutExpiry(state.ExpiryEntry{ @@ -3054,7 +3054,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.RegisterSubnetValidator](t)(message.NewRegisterSubnetValidator( + must[*message.RegisterL1Validator](t)(message.NewRegisterL1Validator( subnetID, nodeID, initialPoP.PublicKey, // Wrong public key @@ -3099,7 +3099,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { { name: "duplicate subnetID + nodeID pair", updateExecutor: func(e *standardTxExecutor) error { - return e.state.PutSubnetOnlyValidator(state.SubnetOnlyValidator{ + return e.state.PutL1Validator(state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: subnetID, NodeID: nodeID, @@ -3107,7 +3107,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { Weight: 1, }) }, - expectedErr: state.ErrDuplicateSubnetOnlyValidator, + expectedErr: state.ErrDuplicateL1Validator, }, { name: "valid tx", @@ -3117,7 +3117,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - // Create the RegisterSubnetValidatorTx + // Create the RegisterL1ValidatorTx wallet := txstest.NewWallet( t, ctx, @@ -3129,7 +3129,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { nil, // chainIDs ) - registerSubnetValidatorTx, err := wallet.IssueRegisterSubnetValidatorTx( + registerL1ValidatorTx, err := wallet.IssueRegisterL1ValidatorTx( test.balance, pop.ProofOfPossession, warpMessage.Bytes(), @@ -3137,7 +3137,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { ) require.NoError(err) - unsignedTx := registerSubnetValidatorTx.Unsigned.(*txs.RegisterSubnetValidatorTx) + unsignedTx := registerL1ValidatorTx.Unsigned.(*txs.RegisterL1ValidatorTx) if test.message != nil { unsignedTx.Message = test.message } @@ -3157,32 +3157,32 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { Ctx: ctx, }, feeCalculator: state.PickFeeCalculator(defaultConfig, baseState), - tx: registerSubnetValidatorTx, + tx: registerL1ValidatorTx, state: diff, } if test.updateExecutor != nil { require.NoError(test.updateExecutor(executor)) } - err = registerSubnetValidatorTx.Unsigned.Visit(executor) + err = registerL1ValidatorTx.Unsigned.Visit(executor) require.ErrorIs(err, test.expectedErr) if err != nil { return } - for utxoID := range registerSubnetValidatorTx.InputIDs() { + for utxoID := range registerL1ValidatorTx.InputIDs() { _, err := diff.GetUTXO(utxoID) require.ErrorIs(err, database.ErrNotFound) } - for _, expectedUTXO := range registerSubnetValidatorTx.UTXOs() { + for _, expectedUTXO := range registerL1ValidatorTx.UTXOs() { utxoID := expectedUTXO.InputID() utxo, err := diff.GetUTXO(utxoID) require.NoError(err) require.Equal(expectedUTXO, utxo) } - sov, err := diff.GetSubnetOnlyValidator(validationID) + l1Validator, err := diff.GetL1Validator(validationID) require.NoError(err) var expectedEndAccumulatedFee uint64 @@ -3190,7 +3190,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { expectedEndAccumulatedFee = test.balance + diff.GetAccruedFees() } require.Equal( - state.SubnetOnlyValidator{ + state.L1Validator{ ValidationID: validationID, SubnetID: subnetID, NodeID: nodeID, @@ -3202,7 +3202,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { MinNonce: 0, EndAccumulatedFee: expectedEndAccumulatedFee, }, - sov, + l1Validator, ) hasExpiry, err := diff.HasExpiry(state.ExpiryEntry{ @@ -3215,7 +3215,7 @@ func TestStandardExecutorRegisterSubnetValidatorTx(t *testing.T) { } } -func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { +func TestStandardExecutorSetL1ValidatorWeightTx(t *testing.T) { var ( fx = &secp256k1fx.Fx{} vm = &secp256k1fx.TestVM{ @@ -3292,7 +3292,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { subnetID = createSubnetTx.ID() chainID = ids.GenerateTestID() address = utils.RandomBytes(32) - validator = &txs.ConvertSubnetValidator{ + validator = &txs.ConvertSubnetToL1Validator{ NodeID: ids.GenerateTestNodeID().Bytes(), Weight: initialWeight, Balance: balance, @@ -3311,11 +3311,11 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { validationID = subnetID.Append(0) ) - convertSubnetTx, err := wallet.IssueConvertSubnetTx( + convertSubnetToL1Tx, err := wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ validator, }, ) @@ -3325,14 +3325,14 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { _, _, _, err = StandardTx( backend, feeCalculator, - convertSubnetTx, + convertSubnetToL1Tx, diff, ) require.NoError(t, err) require.NoError(t, diff.Apply(baseState)) require.NoError(t, baseState.Commit()) - initialSoV, err := baseState.GetSubnetOnlyValidator(validationID) + initialL1Validator, err := baseState.GetL1Validator(validationID) require.NoError(t, err) // Create the Warp messages @@ -3345,7 +3345,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( validationID, nonce, weight, @@ -3371,7 +3371,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( validationID, nonce, 0, @@ -3383,11 +3383,11 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { increaseL1Weight := func(weight uint64) func(*standardTxExecutor) error { return func(e *standardTxExecutor) error { - sov := initialSoV - sov.ValidationID = ids.GenerateTestID() - sov.NodeID = ids.GenerateTestNodeID() - sov.Weight = weight - return e.state.PutSubnetOnlyValidator(sov) + l1Validator := initialL1Validator + l1Validator.ValidationID = ids.GenerateTestID() + l1Validator.NodeID = ids.GenerateTestNodeID() + l1Validator.Weight = weight + return e.state.PutL1Validator(l1Validator) } } @@ -3470,7 +3470,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetConversion](t)(message.NewSubnetConversion(ids.Empty)).Bytes(), + must[*message.SubnetToL1Conversion](t)(message.NewSubnetToL1Conversion(ids.Empty)).Bytes(), )).Bytes(), )), warpSignature, @@ -3485,7 +3485,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( validationID, math.MaxUint64, 1, @@ -3497,14 +3497,14 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { expectedErr: message.ErrNonceReservedForRemoval, }, { - name: "SoV not found", + name: "L1 validator not found", message: must[*warp.Message](t)(warp.NewMessage( must[*warp.UnsignedMessage](t)(warp.NewUnsignedMessage( ctx.NetworkID, chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( ids.GenerateTestID(), // invalid initialValidationID nonce, weight, @@ -3513,21 +3513,21 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { )), warpSignature, )).Bytes(), - expectedErr: errCouldNotLoadSoV, + expectedErr: errCouldNotLoadL1Validator, }, { name: "nonce too low", updateExecutor: func(e *standardTxExecutor) error { - sov := initialSoV - sov.MinNonce = nonce + 1 - return e.state.PutSubnetOnlyValidator(sov) + l1Validator := initialL1Validator + l1Validator.MinNonce = nonce + 1 + return e.state.PutL1Validator(l1Validator) }, expectedErr: errWarpMessageContainsStaleNonce, }, { name: "invalid source chain", updateExecutor: func(e *standardTxExecutor) error { - e.state.SetSubnetConversion(subnetID, state.SubnetConversion{}) + e.state.SetSubnetToL1Conversion(subnetID, state.SubnetToL1Conversion{}) return nil }, expectedErr: errWrongWarpMessageSourceChainID, @@ -3535,7 +3535,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { { name: "invalid source address", updateExecutor: func(e *standardTxExecutor) error { - e.state.SetSubnetConversion(subnetID, state.SubnetConversion{ + e.state.SetSubnetToL1Conversion(subnetID, state.SubnetToL1Conversion{ ChainID: chainID, }) return nil @@ -3556,9 +3556,9 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { return err } - sov := initialSoV - sov.EndAccumulatedFee = 0 // Deactivate the validator - return e.state.PutSubnetOnlyValidator(sov) + l1Validator := initialL1Validator + l1Validator.EndAccumulatedFee = 0 // Deactivate the validator + return e.state.PutL1Validator(l1Validator) }, }, { @@ -3569,7 +3569,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { chainID, must[*payload.AddressedCall](t)(payload.NewAddressedCall( address, - must[*message.SubnetValidatorWeight](t)(message.NewSubnetValidatorWeight( + must[*message.L1ValidatorWeight](t)(message.NewL1ValidatorWeight( validationID, math.MaxUint64, 0, @@ -3584,16 +3584,16 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { return err } - sov := initialSoV - sov.EndAccumulatedFee = 0 // Deactivate the validator - return e.state.PutSubnetOnlyValidator(sov) + l1Validator := initialL1Validator + l1Validator.EndAccumulatedFee = 0 // Deactivate the validator + return e.state.PutL1Validator(l1Validator) }, }, { name: "should have been previously deactivated", message: removeValidatorWarpMessage.Bytes(), updateExecutor: func(e *standardTxExecutor) error { - e.state.SetAccruedFees(initialSoV.EndAccumulatedFee) + e.state.SetAccruedFees(initialL1Validator.EndAccumulatedFee) return increaseL1Weight(1)(e) }, expectedErr: errStateCorruption, @@ -3630,7 +3630,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - // Create the SetSubnetValidatorWeightTx + // Create the SetL1ValidatorWeightTx wallet := txstest.NewWallet( t, ctx, @@ -3646,7 +3646,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { if message == nil { message = increaseWeightWarpMessage.Bytes() } - setSubnetValidatorWeightTx, err := wallet.IssueSetSubnetValidatorWeightTx( + setL1ValidatorWeightTx, err := wallet.IssueSetL1ValidatorWeightTx( message, test.builderOptions..., ) @@ -3664,25 +3664,25 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { Ctx: ctx, }, feeCalculator: state.PickFeeCalculator(defaultConfig, baseState), - tx: setSubnetValidatorWeightTx, + tx: setL1ValidatorWeightTx, state: diff, } if test.updateExecutor != nil { require.NoError(test.updateExecutor(executor)) } - err = setSubnetValidatorWeightTx.Unsigned.Visit(executor) + err = setL1ValidatorWeightTx.Unsigned.Visit(executor) require.ErrorIs(err, test.expectedErr) if err != nil { return } - for utxoID := range setSubnetValidatorWeightTx.InputIDs() { + for utxoID := range setL1ValidatorWeightTx.InputIDs() { _, err := diff.GetUTXO(utxoID) require.ErrorIs(err, database.ErrNotFound) } - baseTxOutputUTXOs := setSubnetValidatorWeightTx.UTXOs() + baseTxOutputUTXOs := setL1ValidatorWeightTx.UTXOs() for _, expectedUTXO := range baseTxOutputUTXOs { utxoID := expectedUTXO.InputID() utxo, err := diff.GetUTXO(utxoID) @@ -3690,20 +3690,20 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { require.Equal(expectedUTXO, utxo) } - sov, err := diff.GetSubnetOnlyValidator(validationID) + l1Validator, err := diff.GetL1Validator(validationID) if test.expectedWeight != 0 { require.NoError(err) - expectedSoV := initialSoV - expectedSoV.MinNonce = test.expectedNonce - expectedSoV.Weight = test.expectedWeight - require.Equal(expectedSoV, sov) + expectedL1Validator := initialL1Validator + expectedL1Validator.MinNonce = test.expectedNonce + expectedL1Validator.Weight = test.expectedWeight + require.Equal(expectedL1Validator, l1Validator) return } require.ErrorIs(err, database.ErrNotFound) utxoID := avax.UTXOID{ - TxID: setSubnetValidatorWeightTx.ID(), + TxID: setL1ValidatorWeightTx.ID(), OutputIndex: uint32(len(baseTxOutputUTXOs)), } inputID := utxoID.InputID() @@ -3720,7 +3720,7 @@ func TestStandardExecutorSetSubnetValidatorWeightTx(t *testing.T) { } } -func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { +func TestStandardExecutorIncreaseL1ValidatorBalanceTx(t *testing.T) { var ( fx = &secp256k1fx.Fx{} vm = &secp256k1fx.TestVM{ @@ -3797,7 +3797,7 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { subnetID = createSubnetTx.ID() chainID = ids.GenerateTestID() address = utils.RandomBytes(32) - validator = &txs.ConvertSubnetValidator{ + validator = &txs.ConvertSubnetToL1Validator{ NodeID: ids.GenerateTestNodeID().Bytes(), Weight: weight, Balance: initialBalance, @@ -3816,11 +3816,11 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { validationID = subnetID.Append(0) ) - convertSubnetTx, err := wallet.IssueConvertSubnetTx( + convertSubnetToL1Tx, err := wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ validator, }, ) @@ -3830,14 +3830,14 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { _, _, _, err = StandardTx( backend, feeCalculator, - convertSubnetTx, + convertSubnetToL1Tx, diff, ) require.NoError(t, err) require.NoError(t, diff.Apply(baseState)) require.NoError(t, baseState.Commit()) - initialSoV, err := baseState.GetSubnetOnlyValidator(validationID) + initialL1Validator, err := baseState.GetL1Validator(validationID) require.NoError(t, err) const balanceIncrease = units.NanoAvax @@ -3845,7 +3845,7 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { name string validationID ids.ID builderOptions []common.Option - updateTx func(*txs.IncreaseBalanceTx) + updateTx func(*txs.IncreaseL1ValidatorBalanceTx) updateExecutor func(*standardTxExecutor) error expectedBalance uint64 expectedErr error @@ -3885,7 +3885,7 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { }, { name: "fee overflow", - updateTx: func(tx *txs.IncreaseBalanceTx) { + updateTx: func(tx *txs.IncreaseL1ValidatorBalanceTx) { tx.Balance = math.MaxUint64 }, expectedErr: safemath.ErrOverflow, @@ -3943,7 +3943,7 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - // Create the IncreaseBalanceTx + // Create the IncreaseL1ValidatorBalanceTx wallet := txstest.NewWallet( t, ctx, @@ -3955,14 +3955,14 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { nil, // chainIDs ) - increaseBalanceTx, err := wallet.IssueIncreaseBalanceTx( + increaseL1ValidatorBalanceTx, err := wallet.IssueIncreaseL1ValidatorBalanceTx( test.validationID, balanceIncrease, test.builderOptions..., ) require.NoError(err) - unsignedTx := increaseBalanceTx.Unsigned.(*txs.IncreaseBalanceTx) + unsignedTx := increaseL1ValidatorBalanceTx.Unsigned.(*txs.IncreaseL1ValidatorBalanceTx) if test.updateTx != nil { test.updateTx(unsignedTx) } @@ -3979,7 +3979,7 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { Ctx: ctx, }, feeCalculator: state.PickFeeCalculator(defaultConfig, baseState), - tx: increaseBalanceTx, + tx: increaseL1ValidatorBalanceTx, state: diff, } if test.updateExecutor != nil { @@ -3992,12 +3992,12 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { return } - for utxoID := range increaseBalanceTx.InputIDs() { + for utxoID := range increaseL1ValidatorBalanceTx.InputIDs() { _, err := diff.GetUTXO(utxoID) require.ErrorIs(err, database.ErrNotFound) } - baseTxOutputUTXOs := increaseBalanceTx.UTXOs() + baseTxOutputUTXOs := increaseL1ValidatorBalanceTx.UTXOs() for _, expectedUTXO := range baseTxOutputUTXOs { utxoID := expectedUTXO.InputID() utxo, err := diff.GetUTXO(utxoID) @@ -4005,17 +4005,17 @@ func TestStandardExecutorIncreaseBalanceTx(t *testing.T) { require.Equal(expectedUTXO, utxo) } - sov, err := diff.GetSubnetOnlyValidator(validationID) + l1Validator, err := diff.GetL1Validator(validationID) require.NoError(err) - expectedSoV := initialSoV - expectedSoV.EndAccumulatedFee = test.expectedBalance - require.Equal(expectedSoV, sov) + expectedL1Validator := initialL1Validator + expectedL1Validator.EndAccumulatedFee = test.expectedBalance + require.Equal(expectedL1Validator, l1Validator) }) } } -func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { +func TestStandardExecutorDisableL1ValidatorTx(t *testing.T) { var ( fx = &secp256k1fx.Fx{} vm = &secp256k1fx.TestVM{ @@ -4093,7 +4093,7 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { subnetID = createSubnetTx.ID() chainID = ids.GenerateTestID() address = utils.RandomBytes(32) - validator = &txs.ConvertSubnetValidator{ + validator = &txs.ConvertSubnetToL1Validator{ NodeID: ids.GenerateTestNodeID().Bytes(), Weight: weight, Balance: initialBalance, @@ -4116,11 +4116,11 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { validationID = subnetID.Append(0) ) - convertSubnetTx, err := wallet.IssueConvertSubnetTx( + convertSubnetToL1Tx, err := wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ validator, }, ) @@ -4130,21 +4130,21 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { _, _, _, err = StandardTx( backend, feeCalculator, - convertSubnetTx, + convertSubnetToL1Tx, diff, ) require.NoError(t, err) require.NoError(t, diff.Apply(baseState)) require.NoError(t, baseState.Commit()) - initialSoV, err := baseState.GetSubnetOnlyValidator(validationID) + initialL1Validator, err := baseState.GetL1Validator(validationID) require.NoError(t, err) tests := []struct { name string validationID ids.ID builderOptions []common.Option - updateTx func(*txs.DisableSubnetValidatorTx) + updateTx func(*txs.DisableL1ValidatorTx) updateExecutor func(*standardTxExecutor) error expectedBalance uint64 expectedErr error @@ -4175,14 +4175,14 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { expectedErr: avax.ErrMemoTooLarge, }, { - name: "sov not found", + name: "l1Validator not found", validationID: ids.GenerateTestID(), - expectedErr: errCouldNotLoadSoV, + expectedErr: errCouldNotLoadL1Validator, }, { name: "not authorized", validationID: validationID, - updateTx: func(tx *txs.DisableSubnetValidatorTx) { + updateTx: func(tx *txs.DisableL1ValidatorTx) { tx.DisableAuth.(*secp256k1fx.Input).SigIndices[0]++ }, expectedErr: errUnauthorizedModification, @@ -4200,9 +4200,9 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { name: "already deactivated", validationID: validationID, updateExecutor: func(e *standardTxExecutor) error { - sov := initialSoV - sov.EndAccumulatedFee = 0 - return e.state.PutSubnetOnlyValidator(sov) + l1Validator := initialL1Validator + l1Validator.EndAccumulatedFee = 0 + return e.state.PutL1Validator(l1Validator) }, expectedBalance: 0, }, @@ -4225,7 +4225,7 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - // Create the DisableSubnetValidatorTx + // Create the DisableL1ValidatorTx wallet := txstest.NewWallet( t, ctx, @@ -4237,13 +4237,13 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { nil, // chainIDs ) - disableSubnetValidatorTx, err := wallet.IssueDisableSubnetValidatorTx( + disableL1ValidatorTx, err := wallet.IssueDisableL1ValidatorTx( validationID, test.builderOptions..., ) require.NoError(err) - unsignedTx := disableSubnetValidatorTx.Unsigned.(*txs.DisableSubnetValidatorTx) + unsignedTx := disableL1ValidatorTx.Unsigned.(*txs.DisableL1ValidatorTx) unsignedTx.ValidationID = test.validationID if test.updateTx != nil { test.updateTx(unsignedTx) @@ -4261,7 +4261,7 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { Ctx: ctx, }, feeCalculator: state.PickFeeCalculator(defaultConfig, baseState), - tx: disableSubnetValidatorTx, + tx: disableL1ValidatorTx, state: diff, } if test.updateExecutor != nil { @@ -4274,12 +4274,12 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { return } - for utxoID := range disableSubnetValidatorTx.InputIDs() { + for utxoID := range disableL1ValidatorTx.InputIDs() { _, err := diff.GetUTXO(utxoID) require.ErrorIs(err, database.ErrNotFound) } - baseTxOutputUTXOs := disableSubnetValidatorTx.UTXOs() + baseTxOutputUTXOs := disableL1ValidatorTx.UTXOs() for _, expectedUTXO := range baseTxOutputUTXOs { utxoID := expectedUTXO.InputID() utxo, err := diff.GetUTXO(utxoID) @@ -4287,15 +4287,15 @@ func TestStandardExecutorDisableSubnetValidatorTx(t *testing.T) { require.Equal(expectedUTXO, utxo) } - sov, err := diff.GetSubnetOnlyValidator(validationID) + l1Validator, err := diff.GetL1Validator(validationID) require.NoError(err) - expectedSoV := initialSoV - expectedSoV.EndAccumulatedFee = 0 - require.Equal(expectedSoV, sov) + expectedL1Validator := initialL1Validator + expectedL1Validator.EndAccumulatedFee = 0 + require.Equal(expectedL1Validator, l1Validator) utxoID := avax.UTXOID{ - TxID: disableSubnetValidatorTx.ID(), + TxID: disableL1ValidatorTx.ID(), OutputIndex: uint32(len(baseTxOutputUTXOs)), } inputID := utxoID.InputID() diff --git a/vms/platformvm/txs/executor/state_changes.go b/vms/platformvm/txs/executor/state_changes.go index a9ce2b44876b..ad5bcd2568ed 100644 --- a/vms/platformvm/txs/executor/state_changes.go +++ b/vms/platformvm/txs/executor/state_changes.go @@ -236,7 +236,7 @@ func advanceTimeTo( seconds := uint64(newChainTime.Sub(previousChainTime) / time.Second) advanceDynamicFeeState(backend.Config.DynamicFeeConfig, changes, seconds) - sovsChanged, err := advanceValidatorFeeState( + l1ValidatorsChanged, err := advanceValidatorFeeState( backend.Config.ValidatorFeeConfig, parentState, changes, @@ -245,7 +245,7 @@ func advanceTimeTo( if err != nil { return nil, false, fmt.Errorf("failed to advance validator fee state: %w", err) } - changed = changed || sovsChanged + changed = changed || l1ValidatorsChanged changes.SetTimestamp(newChainTime) return changes, changed, nil @@ -300,9 +300,9 @@ func advanceDynamicFeeState( changes.SetFeeState(dynamicFeeState) } -// advanceValidatorFeeState advances the validator fee state by [seconds]. SoVs -// are read from [parentState] and written to [changes] to avoid modifying state -// while an iterator is held. +// advanceValidatorFeeState advances the validator fee state by [seconds]. L1 +// validators are read from [parentState] and written to [changes] to avoid +// modifying state while an iterator is held. func advanceValidatorFeeState( config fee.Config, parentState state.Chain, @@ -310,8 +310,8 @@ func advanceValidatorFeeState( seconds uint64, ) (bool, error) { validatorFeeState := fee.State{ - Current: gas.Gas(changes.NumActiveSubnetOnlyValidators()), - Excess: changes.GetSoVExcess(), + Current: gas.Gas(changes.NumActiveL1Validators()), + Excess: changes.GetL1ValidatorExcess(), } validatorCost := validatorFeeState.CostOf(config, seconds) @@ -324,30 +324,30 @@ func advanceValidatorFeeState( // Invariant: It is not safe to modify the state while iterating over it, // so we use the parentState's iterator rather than the changes iterator. // ParentState must not be modified before this iterator is released. - sovIterator, err := parentState.GetActiveSubnetOnlyValidatorsIterator() + l1ValidatorIterator, err := parentState.GetActiveL1ValidatorsIterator() if err != nil { - return false, fmt.Errorf("could not iterate over active SoVs: %w", err) + return false, fmt.Errorf("could not iterate over active L1 validators: %w", err) } - defer sovIterator.Release() + defer l1ValidatorIterator.Release() var changed bool - for sovIterator.Next() { - sov := sovIterator.Value() - // GetActiveSubnetOnlyValidatorsIterator iterates in order of increasing + for l1ValidatorIterator.Next() { + l1Validator := l1ValidatorIterator.Value() + // GetActiveL1ValidatorsIterator iterates in order of increasing // EndAccumulatedFee, so we can break early. - if sov.EndAccumulatedFee > accruedFees { + if l1Validator.EndAccumulatedFee > accruedFees { break } - sov.EndAccumulatedFee = 0 // Deactivate the validator - if err := changes.PutSubnetOnlyValidator(sov); err != nil { - return false, fmt.Errorf("could not deactivate SoV %s: %w", sov.ValidationID, err) + l1Validator.EndAccumulatedFee = 0 // Deactivate the validator + if err := changes.PutL1Validator(l1Validator); err != nil { + return false, fmt.Errorf("could not deactivate L1 validator %s: %w", l1Validator.ValidationID, err) } changed = true } validatorFeeState = validatorFeeState.AdvanceTime(config.Target, seconds) - changes.SetSoVExcess(validatorFeeState.Excess) + changes.SetL1ValidatorExcess(validatorFeeState.Excess) changes.SetAccruedFees(accruedFees) return changed, nil } diff --git a/vms/platformvm/txs/executor/state_changes_test.go b/vms/platformvm/txs/executor/state_changes_test.go index 339894e57100..5b78d790f8af 100644 --- a/vms/platformvm/txs/executor/state_changes_test.go +++ b/vms/platformvm/txs/executor/state_changes_test.go @@ -227,7 +227,7 @@ func TestAdvanceTimeTo_RemovesStaleExpiries(t *testing.T) { } } -func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { +func TestAdvanceTimeTo_UpdateL1Validators(t *testing.T) { sk, err := bls.NewSecretKey() require.NoError(t, err) @@ -240,8 +240,8 @@ func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { pk = bls.PublicFromSecretKey(sk) pkBytes = bls.PublicKeyToUncompressedBytes(pk) - newSoV = func(endAccumulatedFee uint64) state.SubnetOnlyValidator { - return state.SubnetOnlyValidator{ + newL1Validator = func(endAccumulatedFee uint64) state.L1Validator { + return state.L1Validator{ ValidationID: ids.GenerateTestID(), SubnetID: ids.GenerateTestID(), NodeID: ids.GenerateTestNodeID(), @@ -250,9 +250,9 @@ func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { EndAccumulatedFee: endAccumulatedFee, } } - sovToEvict0 = newSoV(3 * units.NanoAvax) // lasts 3 seconds - sovToEvict1 = newSoV(3 * units.NanoAvax) // lasts 3 seconds - sovToKeep = newSoV(units.Avax) + l1ValidatorToEvict0 = newL1Validator(3 * units.NanoAvax) // lasts 3 seconds + l1ValidatorToEvict1 = newL1Validator(3 * units.NanoAvax) // lasts 3 seconds + l1ValidatorToKeep = newL1Validator(units.Avax) currentTime = genesistest.DefaultValidatorStartTime newTime = currentTime.Add(timeToAdvance) @@ -269,55 +269,55 @@ func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { ) tests := []struct { - name string - initialSoVs []state.SubnetOnlyValidator - expectedModified bool - expectedSoVs []state.SubnetOnlyValidator - expectedExcess gas.Gas + name string + initialL1Validators []state.L1Validator + expectedModified bool + expectedL1Validators []state.L1Validator + expectedExcess gas.Gas }{ { - name: "no SoVs", + name: "no L1 validators", expectedModified: false, expectedExcess: 0, }, { name: "evicted one", - initialSoVs: []state.SubnetOnlyValidator{ - sovToEvict0, + initialL1Validators: []state.L1Validator{ + l1ValidatorToEvict0, }, expectedModified: true, expectedExcess: 0, }, { name: "evicted all", - initialSoVs: []state.SubnetOnlyValidator{ - sovToEvict0, - sovToEvict1, + initialL1Validators: []state.L1Validator{ + l1ValidatorToEvict0, + l1ValidatorToEvict1, }, expectedModified: true, expectedExcess: 3, }, { name: "evicted 2 of 3", - initialSoVs: []state.SubnetOnlyValidator{ - sovToEvict0, - sovToEvict1, - sovToKeep, + initialL1Validators: []state.L1Validator{ + l1ValidatorToEvict0, + l1ValidatorToEvict1, + l1ValidatorToKeep, }, expectedModified: true, - expectedSoVs: []state.SubnetOnlyValidator{ - sovToKeep, + expectedL1Validators: []state.L1Validator{ + l1ValidatorToKeep, }, expectedExcess: 6, }, { name: "no evictions", - initialSoVs: []state.SubnetOnlyValidator{ - sovToKeep, + initialL1Validators: []state.L1Validator{ + l1ValidatorToKeep, }, expectedModified: false, - expectedSoVs: []state.SubnetOnlyValidator{ - sovToKeep, + expectedL1Validators: []state.L1Validator{ + l1ValidatorToKeep, }, expectedExcess: 0, }, @@ -329,8 +329,8 @@ func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { s = statetest.New(t, statetest.Config{}) ) - for _, sov := range test.initialSoVs { - require.NoError(s.PutSubnetOnlyValidator(sov)) + for _, l1Validator := range test.initialL1Validators { + require.NoError(s.PutL1Validator(l1Validator)) } // Ensure the invariant that [newTime <= nextStakerChangeTime] on @@ -353,14 +353,14 @@ func TestAdvanceTimeTo_UpdateSoVs(t *testing.T) { require.NoError(err) require.Equal(test.expectedModified, validatorsModified) - activeSoVs, err := s.GetActiveSubnetOnlyValidatorsIterator() + activeL1Validators, err := s.GetActiveL1ValidatorsIterator() require.NoError(err) require.Equal( - test.expectedSoVs, - iterator.ToSlice(activeSoVs), + test.expectedL1Validators, + iterator.ToSlice(activeL1Validators), ) - require.Equal(test.expectedExcess, s.GetSoVExcess()) + require.Equal(test.expectedExcess, s.GetL1ValidatorExcess()) require.Equal(uint64(secondsToAdvance), s.GetAccruedFees()) }) } diff --git a/vms/platformvm/txs/executor/subnet_tx_verification.go b/vms/platformvm/txs/executor/subnet_tx_verification.go index 3b4140235b23..646ec2fc5f7a 100644 --- a/vms/platformvm/txs/executor/subnet_tx_verification.go +++ b/vms/platformvm/txs/executor/subnet_tx_verification.go @@ -44,7 +44,7 @@ func verifyPoASubnetAuthorization( return nil, err } - _, err = chainState.GetSubnetConversion(subnetID) + _, err = chainState.GetSubnetToL1Conversion(subnetID) if err == nil { return nil, fmt.Errorf("%q %w", subnetID, errIsImmutable) } diff --git a/vms/platformvm/txs/executor/warp_verifier.go b/vms/platformvm/txs/executor/warp_verifier.go index 3347c90d043f..26403d576f4c 100644 --- a/vms/platformvm/txs/executor/warp_verifier.go +++ b/vms/platformvm/txs/executor/warp_verifier.go @@ -102,23 +102,23 @@ func (*warpVerifier) BaseTx(*txs.BaseTx) error { return nil } -func (*warpVerifier) ConvertSubnetTx(*txs.ConvertSubnetTx) error { +func (*warpVerifier) ConvertSubnetToL1Tx(*txs.ConvertSubnetToL1Tx) error { return nil } -func (*warpVerifier) IncreaseBalanceTx(*txs.IncreaseBalanceTx) error { +func (*warpVerifier) IncreaseL1ValidatorBalanceTx(*txs.IncreaseL1ValidatorBalanceTx) error { return nil } -func (*warpVerifier) DisableSubnetValidatorTx(*txs.DisableSubnetValidatorTx) error { +func (*warpVerifier) DisableL1ValidatorTx(*txs.DisableL1ValidatorTx) error { return nil } -func (w *warpVerifier) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) error { +func (w *warpVerifier) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error { return w.verify(tx.Message) } -func (w *warpVerifier) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) error { +func (w *warpVerifier) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error { return w.verify(tx.Message) } diff --git a/vms/platformvm/txs/executor/warp_verifier_test.go b/vms/platformvm/txs/executor/warp_verifier_test.go index 2f862cb2b2b0..ed58da9d0752 100644 --- a/vms/platformvm/txs/executor/warp_verifier_test.go +++ b/vms/platformvm/txs/executor/warp_verifier_test.go @@ -151,52 +151,52 @@ func TestVerifyWarpMessages(t *testing.T) { tx: &txs.BaseTx{}, }, { - name: "ConvertSubnetTx", - tx: &txs.ConvertSubnetTx{}, + name: "ConvertSubnetToL1Tx", + tx: &txs.ConvertSubnetToL1Tx{}, }, { - name: "RegisterSubnetValidatorTx with unparsable message", - tx: &txs.RegisterSubnetValidatorTx{}, + name: "RegisterL1ValidatorTx with unparsable message", + tx: &txs.RegisterL1ValidatorTx{}, expectedErr: codec.ErrCantUnpackVersion, }, { - name: "RegisterSubnetValidatorTx with invalid message", - tx: &txs.RegisterSubnetValidatorTx{ + name: "RegisterL1ValidatorTx with invalid message", + tx: &txs.RegisterL1ValidatorTx{ Message: invalidWarpMessage.Bytes(), }, expectedErr: warp.ErrWrongNetworkID, }, { - name: "RegisterSubnetValidatorTx with valid message", - tx: &txs.RegisterSubnetValidatorTx{ + name: "RegisterL1ValidatorTx with valid message", + tx: &txs.RegisterL1ValidatorTx{ Message: validWarpMessage.Bytes(), }, }, { - name: "SetSubnetValidatorWeightTx with unparsable message", - tx: &txs.SetSubnetValidatorWeightTx{}, + name: "SetL1ValidatorWeightTx with unparsable message", + tx: &txs.SetL1ValidatorWeightTx{}, expectedErr: codec.ErrCantUnpackVersion, }, { - name: "SetSubnetValidatorWeightTx with invalid message", - tx: &txs.SetSubnetValidatorWeightTx{ + name: "SetL1ValidatorWeightTx with invalid message", + tx: &txs.SetL1ValidatorWeightTx{ Message: invalidWarpMessage.Bytes(), }, expectedErr: warp.ErrWrongNetworkID, }, { - name: "SetSubnetValidatorWeightTx with valid message", - tx: &txs.SetSubnetValidatorWeightTx{ + name: "SetL1ValidatorWeightTx with valid message", + tx: &txs.SetL1ValidatorWeightTx{ Message: validWarpMessage.Bytes(), }, }, { - name: "IncreaseBalanceTx", - tx: &txs.IncreaseBalanceTx{}, + name: "IncreaseL1ValidatorBalanceTx", + tx: &txs.IncreaseL1ValidatorBalanceTx{}, }, { - name: "DisableSubnetValidatorTx", - tx: &txs.DisableSubnetValidatorTx{}, + name: "DisableL1ValidatorTx", + tx: &txs.DisableL1ValidatorTx{}, }, } for _, test := range tests { diff --git a/vms/platformvm/txs/fee/calculator_test.go b/vms/platformvm/txs/fee/calculator_test.go index c128c278c856..cef21b05a38e 100644 --- a/vms/platformvm/txs/fee/calculator_test.go +++ b/vms/platformvm/txs/fee/calculator_test.go @@ -220,61 +220,61 @@ var ( expectedDynamicFee: 173_600, }, { - name: "ConvertSubnetTx", + name: "ConvertSubnetToL1Tx", tx: "00000000002300003039000000000000000000000000000000000000000000000000000000000000000000000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000007002386f234262960000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000001705f3d4415f990225d3df5ce437d7af2aa324b1bbce854ee34ab6f39882250d200000000dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005002386f26fc0f94e000000010000000000000000a0673b4ee5ec44e57c8ab250dd7cd7b68d04421f64bd6559a4284a3ee358ff2b705f3d4415f990225d3df5ce437d7af2aa324b1bbce854ee34ab6f39882250d2000000000000000100000014c582872c37c81efa2c94ea347af49cdc23a830aa000000000000c137000000003b9aca00a3783a891cb41cadbfcf456da149f30e7af972677a162b984bef0779f254baac51ec042df1781d1295df80fb41c801269731fc6c25e1e5940dc3cb8509e30348fa712742cfdc83678acc9f95908eb98b89b28802fb559b4a2a6ff3216707c07f0ceb0b45a95f4f9a9540bbd3331d8ab4f233bffa4abb97fad9d59a1695f31b92a2b89e365facf7ab8c30de7c4a496d1e000000000000000000000000000000000000000a00000001000000000000000200000009000000011430759900fdf516cdeff6a1390dd7438585568a89c06142c44b3bf1178c4cae4bff44e955b19da08f0359d396a7a738b989bb46377e7465cd858ddd1e8dd3790100000009000000011430759900fdf516cdeff6a1390dd7438585568a89c06142c44b3bf1178c4cae4bff44e955b19da08f0359d396a7a738b989bb46377e7465cd858ddd1e8dd37901", expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 656, // The length of the tx in bytes - gas.DBRead: IntrinsicConvertSubnetTxComplexities[gas.DBRead] + intrinsicInputDBRead, - gas.DBWrite: IntrinsicConvertSubnetTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite + intrinsicConvertSubnetValidatorDBWrite, + gas.DBRead: IntrinsicConvertSubnetToL1TxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBWrite: IntrinsicConvertSubnetToL1TxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite + intrinsicConvertSubnetToL1ValidatorDBWrite, gas.Compute: 0, // TODO: implement }, expectedDynamicFee: 365_600, }, { - name: "RegisterSubnetValidatorTx", + name: "RegisterL1ValidatorTx", tx: "00000000002400003039000000000000000000000000000000000000000000000000000000000000000000000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000007002386f1f88b552a000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000001ca44ad45a63381b07074be7f82005c41550c989b967f40020f3bedc4b02191f300000000dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005002386f234262404000000010000000000000000000000003b9aca00ab5cb0516b7afdb13727f766185b2b8da44e2653eef63c85f196701083e649289cce1a23c39eb471b2473bc6872aa3ea190de0fe66296cbdd4132c92c3430ff22f28f0b341b15905a005bbd66cc0f4056bc4be5934e4f3a57151a60060f429190000012f000000003039705f3d4415f990225d3df5ce437d7af2aa324b1bbce854ee34ab6f39882250d20000009c000000000001000000000000008e000000000001a0673b4ee5ec44e57c8ab250dd7cd7b68d04421f64bd6559a4284a3ee358ff2b000000145efc86a11c5b12cc95b2cf527c023f9cf6e0e8f6b62034315c5d11cea4190f6ea8997821c02483d29adb5e4567843f7a44c39b2ffa20c8520dc358702fb1ec29f2746dcc000000006705af280000000000000000000000000000000000000000000000010000000000000001018e99dc6ed736089c03b9a1275e0cf801524ed341fb10111f29c0390fa2f96cf6aa78539ec767e5cd523c606c7ede50e60ba6065a3685e770d979b0df74e3541b61ed63f037463776098576e385767a695de59352b44e515831c5ee7a8cc728f9000000010000000900000001a0950b9e6e866130f0d09e2a7bfdd0246513295237258afa942b1850dab79824605c796bbfc9223cf91935fb29c66f8b927690220b9b1c24d6f078054a3e346201", expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 710, // The length of the tx in bytes - gas.DBRead: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, - gas.DBWrite: IntrinsicRegisterSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, + gas.DBRead: IntrinsicRegisterL1ValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBWrite: IntrinsicRegisterL1ValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 0, // TODO: implement }, expectedDynamicFee: 151_000, }, { - name: "SetSubnetValidatorWeightTx", + name: "SetL1ValidatorWeightTx", tx: "00000000002500003039000000000000000000000000000000000000000000000000000000000000000000000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000007002386f1f88b5100000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000001389c41b6ed301e4c118bd23673268fd2054b772efcf25685a117b74bab7ae5e400000000dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005002386f1f88b552a000000010000000000000000000000d7000000003039705f3d4415f990225d3df5ce437d7af2aa324b1bbce854ee34ab6f39882250d200000044000000000001000000000000003600000000000338e6e9fe31c6d070a8c792dbacf6d0aefb8eac2aded49cc0aa9f422d1fdd9ecd0000000000000001000000000000000500000000000000010187f4bb2c42869c56f023a1ca81045aff034acd490b8f15b5069025f982e605e077007fc588f7d56369a65df7574df3b70ff028ea173739c789525ab7eebfcb5c115b13cca8f02b362104b700c75bc95234109f3f1360ddcb4ec3caf6b0e821cb0000000100000009000000010a29f3c86d52908bf2efbc3f918a363df704c429d66c8d6615712a2a584a2a5f264a9e7b107c07122a06f31cadc2f51285884d36fe8df909a07467417f1d64cf00", expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 518, // The length of the tx in bytes - gas.DBRead: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBRead] + intrinsicInputDBRead, - gas.DBWrite: IntrinsicSetSubnetValidatorWeightTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, + gas.DBRead: IntrinsicSetL1ValidatorWeightTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBWrite: IntrinsicSetL1ValidatorWeightTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 0, // TODO: implement }, expectedDynamicFee: 131_800, }, { - name: "IncreaseBalanceTx", + name: "IncreaseL1ValidatorBalanceTx", tx: "00000000002600003039000000000000000000000000000000000000000000000000000000000000000000000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000007002386f1f88b4e52000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000001f61ea7e3bb6d33da9901644f3c623e4537b7d1c276e9ef23bcc8e4150e494d6600000000dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005002386f1f88b510000000001000000000000000038e6e9fe31c6d070a8c792dbacf6d0aefb8eac2aded49cc0aa9f422d1fdd9ecd0000000000000002000000010000000900000001cb56b56387be9186d86430fad5418db4d13e991b6805b6ba178b719e3f47ce001da52d6ed3173bfdd8b69940a135432abce493a10332e881f6c34cea3617595e00", expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 339, // The length of the tx in bytes - gas.DBRead: IntrinsicIncreaseBalanceTxComplexities[gas.DBRead] + intrinsicInputDBRead, - gas.DBWrite: IntrinsicIncreaseBalanceTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, + gas.DBRead: IntrinsicIncreaseL1ValidatorBalanceTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBWrite: IntrinsicIncreaseL1ValidatorBalanceTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 0, // TODO: implement }, expectedDynamicFee: 113_900, }, { - name: "DisableSubnetValidatorTx", + name: "DisableL1ValidatorTx", tx: "00000000002700003039000000000000000000000000000000000000000000000000000000000000000000000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000007002386f1f88b4b9e000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000001fd91c5c421468b13b09dda413bdbe1316c7c9417f2468b893071d4cb608a01da00000000dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005002386f1f88b4e5200000001000000000000000038e6e9fe31c6d070a8c792dbacf6d0aefb8eac2aded49cc0aa9f422d1fdd9ecd0000000a00000000000000020000000900000001ff99bb626d898907a660701e2febaa311b4e644fe71add2d1a3f71748102c73f54d73c8370a9ae33e09c984bb8c03da4922bf208af836ec2daaa31cb42788bee010000000900000000", expectedStaticFeeErr: ErrUnsupportedTx, expectedComplexity: gas.Dimensions{ gas.Bandwidth: 347, // The length of the tx in bytes - gas.DBRead: IntrinsicDisableSubnetValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, - gas.DBWrite: IntrinsicDisableSubnetValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, + gas.DBRead: IntrinsicDisableL1ValidatorTxComplexities[gas.DBRead] + intrinsicInputDBRead, + gas.DBWrite: IntrinsicDisableL1ValidatorTxComplexities[gas.DBWrite] + intrinsicInputDBWrite + intrinsicOutputDBWrite, gas.Compute: 0, // TODO: implement }, expectedDynamicFee: 114_700, diff --git a/vms/platformvm/txs/fee/complexity.go b/vms/platformvm/txs/fee/complexity.go index acea57d2c986..db85141ea8f0 100644 --- a/vms/platformvm/txs/fee/complexity.go +++ b/vms/platformvm/txs/fee/complexity.go @@ -64,7 +64,7 @@ const ( intrinsicSECP256k1FxSignatureBandwidth = wrappers.IntLen + // signature index secp256k1.SignatureLen // signature length - intrinsicConvertSubnetValidatorBandwidth = wrappers.IntLen + // nodeID length + intrinsicConvertSubnetToL1ValidatorBandwidth = wrappers.IntLen + // nodeID length wrappers.LongLen + // weight wrappers.LongLen + // balance wrappers.IntLen + // remaining balance owner threshold @@ -77,9 +77,9 @@ const ( intrinsicInputDBRead = 1 - intrinsicInputDBWrite = 1 - intrinsicOutputDBWrite = 1 - intrinsicConvertSubnetValidatorDBWrite = 4 // weight diff + pub key diff + subnetID/nodeID + validationID + intrinsicInputDBWrite = 1 + intrinsicOutputDBWrite = 1 + intrinsicConvertSubnetToL1ValidatorDBWrite = 4 // weight diff + pub key diff + subnetID/nodeID + validationID ) var ( @@ -186,7 +186,7 @@ var ( gas.DBWrite: 0, gas.Compute: 0, } - IntrinsicConvertSubnetTxComplexities = gas.Dimensions{ + IntrinsicConvertSubnetToL1TxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // subnetID ids.IDLen + // chainID @@ -198,7 +198,7 @@ var ( gas.DBWrite: 2, // manager + weight gas.Compute: 0, } - IntrinsicRegisterSubnetValidatorTxComplexities = gas.Dimensions{ + IntrinsicRegisterL1ValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + wrappers.LongLen + // balance bls.SignatureLen + // proof of possession @@ -207,14 +207,14 @@ var ( gas.DBWrite: 0, // TODO gas.Compute: 0, // TODO: Include PoP verification time } - IntrinsicSetSubnetValidatorWeightTxComplexities = gas.Dimensions{ + IntrinsicSetL1ValidatorWeightTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + wrappers.IntLen, // message length gas.DBRead: 0, // TODO gas.DBWrite: 0, // TODO gas.Compute: 0, } - IntrinsicIncreaseBalanceTxComplexities = gas.Dimensions{ + IntrinsicIncreaseL1ValidatorBalanceTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // validationID wrappers.LongLen, // balance @@ -222,7 +222,7 @@ var ( gas.DBWrite: 0, // TODO gas.Compute: 0, } - IntrinsicDisableSubnetValidatorTxComplexities = gas.Dimensions{ + IntrinsicDisableL1ValidatorTxComplexities = gas.Dimensions{ gas.Bandwidth: IntrinsicBaseTxComplexities[gas.Bandwidth] + ids.IDLen + // validationID wrappers.IntLen + // auth typeID @@ -350,17 +350,17 @@ func inputComplexity(in *avax.TransferableInput) (gas.Dimensions, error) { return complexity, err } -// ConvertSubnetValidatorComplexity returns the complexity the validators add to -// a transaction. -func ConvertSubnetValidatorComplexity(sovs ...*txs.ConvertSubnetValidator) (gas.Dimensions, error) { +// ConvertSubnetToL1ValidatorComplexity returns the complexity the validators +// add to a transaction. +func ConvertSubnetToL1ValidatorComplexity(l1Validators ...*txs.ConvertSubnetToL1Validator) (gas.Dimensions, error) { var complexity gas.Dimensions - for _, sov := range sovs { - sovComplexity, err := convertSubnetValidatorComplexity(sov) + for _, l1Validator := range l1Validators { + l1ValidatorComplexity, err := convertSubnetToL1ValidatorComplexity(l1Validator) if err != nil { return gas.Dimensions{}, err } - complexity, err = complexity.Add(&sovComplexity) + complexity, err = complexity.Add(&l1ValidatorComplexity) if err != nil { return gas.Dimensions{}, err } @@ -368,27 +368,27 @@ func ConvertSubnetValidatorComplexity(sovs ...*txs.ConvertSubnetValidator) (gas. return complexity, nil } -func convertSubnetValidatorComplexity(sov *txs.ConvertSubnetValidator) (gas.Dimensions, error) { +func convertSubnetToL1ValidatorComplexity(l1Validator *txs.ConvertSubnetToL1Validator) (gas.Dimensions, error) { complexity := gas.Dimensions{ - gas.Bandwidth: intrinsicConvertSubnetValidatorBandwidth, + gas.Bandwidth: intrinsicConvertSubnetToL1ValidatorBandwidth, gas.DBRead: 0, - gas.DBWrite: intrinsicConvertSubnetValidatorDBWrite, + gas.DBWrite: intrinsicConvertSubnetToL1ValidatorDBWrite, gas.Compute: 0, // TODO: Add compute complexity } - signerComplexity, err := SignerComplexity(&sov.Signer) + signerComplexity, err := SignerComplexity(&l1Validator.Signer) if err != nil { return gas.Dimensions{}, err } - numAddresses := uint64(len(sov.RemainingBalanceOwner.Addresses) + len(sov.DeactivationOwner.Addresses)) + numAddresses := uint64(len(l1Validator.RemainingBalanceOwner.Addresses) + len(l1Validator.DeactivationOwner.Addresses)) addressBandwidth, err := math.Mul(numAddresses, ids.ShortIDLen) if err != nil { return gas.Dimensions{}, err } return complexity.Add( &gas.Dimensions{ - gas.Bandwidth: uint64(len(sov.NodeID)), + gas.Bandwidth: uint64(len(l1Validator.NodeID)), }, &signerComplexity, &gas.Dimensions{ @@ -705,12 +705,12 @@ func (c *complexityVisitor) BaseTx(tx *txs.BaseTx) error { return err } -func (c *complexityVisitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { +func (c *complexityVisitor) ConvertSubnetToL1Tx(tx *txs.ConvertSubnetToL1Tx) error { baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err } - validatorComplexity, err := ConvertSubnetValidatorComplexity(tx.Validators...) + validatorComplexity, err := ConvertSubnetToL1ValidatorComplexity(tx.Validators...) if err != nil { return err } @@ -718,7 +718,7 @@ func (c *complexityVisitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { if err != nil { return err } - c.output, err = IntrinsicConvertSubnetTxComplexities.Add( + c.output, err = IntrinsicConvertSubnetToL1TxComplexities.Add( &baseTxComplexity, &validatorComplexity, &authComplexity, @@ -729,7 +729,7 @@ func (c *complexityVisitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return err } -func (c *complexityVisitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) error { +func (c *complexityVisitor) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error { baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err @@ -738,14 +738,14 @@ func (c *complexityVisitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetVali if err != nil { return err } - c.output, err = IntrinsicRegisterSubnetValidatorTxComplexities.Add( + c.output, err = IntrinsicRegisterL1ValidatorTxComplexities.Add( &baseTxComplexity, &warpComplexity, ) return err } -func (c *complexityVisitor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) error { +func (c *complexityVisitor) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error { baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err @@ -754,25 +754,25 @@ func (c *complexityVisitor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidato if err != nil { return err } - c.output, err = IntrinsicSetSubnetValidatorWeightTxComplexities.Add( + c.output, err = IntrinsicSetL1ValidatorWeightTxComplexities.Add( &baseTxComplexity, &warpComplexity, ) return err } -func (c *complexityVisitor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error { +func (c *complexityVisitor) IncreaseL1ValidatorBalanceTx(tx *txs.IncreaseL1ValidatorBalanceTx) error { baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err } - c.output, err = IntrinsicIncreaseBalanceTxComplexities.Add( + c.output, err = IntrinsicIncreaseL1ValidatorBalanceTxComplexities.Add( &baseTxComplexity, ) return err } -func (c *complexityVisitor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValidatorTx) error { +func (c *complexityVisitor) DisableL1ValidatorTx(tx *txs.DisableL1ValidatorTx) error { baseTxComplexity, err := baseTxComplexity(&tx.BaseTx) if err != nil { return err @@ -781,7 +781,7 @@ func (c *complexityVisitor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValida if err != nil { return err } - c.output, err = IntrinsicDisableSubnetValidatorTxComplexities.Add( + c.output, err = IntrinsicDisableL1ValidatorTxComplexities.Add( &baseTxComplexity, &authComplexity, ) diff --git a/vms/platformvm/txs/fee/complexity_test.go b/vms/platformvm/txs/fee/complexity_test.go index d0767317df3b..82e51382e858 100644 --- a/vms/platformvm/txs/fee/complexity_test.go +++ b/vms/platformvm/txs/fee/complexity_test.go @@ -368,15 +368,15 @@ func TestInputComplexity(t *testing.T) { } } -func TestConvertSubnetValidatorComplexity(t *testing.T) { +func TestConvertSubnetToL1ValidatorComplexity(t *testing.T) { tests := []struct { name string - vdr txs.ConvertSubnetValidator + vdr txs.ConvertSubnetToL1Validator expected gas.Dimensions }{ { name: "any can spend", - vdr: txs.ConvertSubnetValidator{ + vdr: txs.ConvertSubnetToL1Validator{ NodeID: make([]byte, ids.NodeIDLen), Signer: signer.ProofOfPossession{}, RemainingBalanceOwner: message.PChainOwner{}, @@ -391,7 +391,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { }, { name: "single remaining balance owner", - vdr: txs.ConvertSubnetValidator{ + vdr: txs.ConvertSubnetToL1Validator{ NodeID: make([]byte, ids.NodeIDLen), Signer: signer.ProofOfPossession{}, RemainingBalanceOwner: message.PChainOwner{ @@ -411,7 +411,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { }, { name: "single deactivation owner", - vdr: txs.ConvertSubnetValidator{ + vdr: txs.ConvertSubnetToL1Validator{ NodeID: make([]byte, ids.NodeIDLen), Signer: signer.ProofOfPossession{}, RemainingBalanceOwner: message.PChainOwner{}, @@ -434,7 +434,7 @@ func TestConvertSubnetValidatorComplexity(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - actual, err := ConvertSubnetValidatorComplexity(&test.vdr) + actual, err := ConvertSubnetToL1ValidatorComplexity(&test.vdr) require.NoError(err) require.Equal(test.expected, actual) diff --git a/vms/platformvm/txs/fee/static_calculator.go b/vms/platformvm/txs/fee/static_calculator.go index 5eac549400c0..02bc52357d7e 100644 --- a/vms/platformvm/txs/fee/static_calculator.go +++ b/vms/platformvm/txs/fee/static_calculator.go @@ -47,23 +47,23 @@ func (*staticVisitor) RewardValidatorTx(*txs.RewardValidatorTx) error { return ErrUnsupportedTx } -func (*staticVisitor) ConvertSubnetTx(*txs.ConvertSubnetTx) error { +func (*staticVisitor) ConvertSubnetToL1Tx(*txs.ConvertSubnetToL1Tx) error { return ErrUnsupportedTx } -func (*staticVisitor) RegisterSubnetValidatorTx(*txs.RegisterSubnetValidatorTx) error { +func (*staticVisitor) RegisterL1ValidatorTx(*txs.RegisterL1ValidatorTx) error { return ErrUnsupportedTx } -func (*staticVisitor) SetSubnetValidatorWeightTx(*txs.SetSubnetValidatorWeightTx) error { +func (*staticVisitor) SetL1ValidatorWeightTx(*txs.SetL1ValidatorWeightTx) error { return ErrUnsupportedTx } -func (*staticVisitor) IncreaseBalanceTx(*txs.IncreaseBalanceTx) error { +func (*staticVisitor) IncreaseL1ValidatorBalanceTx(*txs.IncreaseL1ValidatorBalanceTx) error { return ErrUnsupportedTx } -func (*staticVisitor) DisableSubnetValidatorTx(*txs.DisableSubnetValidatorTx) error { +func (*staticVisitor) DisableL1ValidatorTx(*txs.DisableL1ValidatorTx) error { return ErrUnsupportedTx } diff --git a/vms/platformvm/txs/increase_balance_tx.go b/vms/platformvm/txs/increase_l1_validator_balance_tx.go similarity index 74% rename from vms/platformvm/txs/increase_balance_tx.go rename to vms/platformvm/txs/increase_l1_validator_balance_tx.go index fd2cc25abcb0..f336cf7db71c 100644 --- a/vms/platformvm/txs/increase_balance_tx.go +++ b/vms/platformvm/txs/increase_l1_validator_balance_tx.go @@ -11,12 +11,12 @@ import ( ) var ( - _ UnsignedTx = (*IncreaseBalanceTx)(nil) + _ UnsignedTx = (*IncreaseL1ValidatorBalanceTx)(nil) ErrZeroBalance = errors.New("balance must be greater than 0") ) -type IncreaseBalanceTx struct { +type IncreaseL1ValidatorBalanceTx struct { // Metadata, inputs and outputs BaseTx `serialize:"true"` // ID corresponding to the validator @@ -25,7 +25,7 @@ type IncreaseBalanceTx struct { Balance uint64 `serialize:"true" json:"balance"` } -func (tx *IncreaseBalanceTx) SyntacticVerify(ctx *snow.Context) error { +func (tx *IncreaseL1ValidatorBalanceTx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: return ErrNilTx @@ -44,6 +44,6 @@ func (tx *IncreaseBalanceTx) SyntacticVerify(ctx *snow.Context) error { return nil } -func (tx *IncreaseBalanceTx) Visit(visitor Visitor) error { - return visitor.IncreaseBalanceTx(tx) +func (tx *IncreaseL1ValidatorBalanceTx) Visit(visitor Visitor) error { + return visitor.IncreaseL1ValidatorBalanceTx(tx) } diff --git a/vms/platformvm/txs/increase_balance_tx_test.go b/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go similarity index 94% rename from vms/platformvm/txs/increase_balance_tx_test.go rename to vms/platformvm/txs/increase_l1_validator_balance_tx_test.go index 2a5fd1a20a64..112782777e64 100644 --- a/vms/platformvm/txs/increase_balance_tx_test.go +++ b/vms/platformvm/txs/increase_l1_validator_balance_tx_test.go @@ -22,10 +22,10 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -//go:embed increase_balance_tx_test.json -var increaseBalanceTxJSON []byte +//go:embed increase_l1_validator_balance_tx_test.json +var increaseL1ValidatorBalanceTxJSON []byte -func TestIncreaseBalanceTxSerialization(t *testing.T) { +func TestIncreaseL1ValidatorBalanceTxSerialization(t *testing.T) { require := require.New(t) var ( @@ -61,7 +61,7 @@ func TestIncreaseBalanceTxSerialization(t *testing.T) { } ) - var unsignedTx UnsignedTx = &IncreaseBalanceTx{ + var unsignedTx UnsignedTx = &IncreaseL1ValidatorBalanceTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -164,7 +164,7 @@ func TestIncreaseBalanceTxSerialization(t *testing.T) { expectedBytes := []byte{ // Codec version 0x00, 0x00, - // IncreaseBalanceTx Type ID + // IncreaseL1ValidatorBalanceTx Type ID 0x00, 0x00, 0x00, 0x26, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -311,12 +311,12 @@ func TestIncreaseBalanceTxSerialization(t *testing.T) { require.NoError(err) require.Equal( // Normalize newlines for Windows - strings.ReplaceAll(string(increaseBalanceTxJSON), "\r\n", "\n"), + strings.ReplaceAll(string(increaseL1ValidatorBalanceTxJSON), "\r\n", "\n"), string(txJSON), ) } -func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { +func TestIncreaseL1ValidatorBalanceTxSyntacticVerify(t *testing.T) { var ( ctx = snowtest.Context(t, ids.GenerateTestID()) validBaseTx = BaseTx{ @@ -328,7 +328,7 @@ func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { ) tests := []struct { name string - tx *IncreaseBalanceTx + tx *IncreaseL1ValidatorBalanceTx expectedErr error }{ { @@ -340,7 +340,7 @@ func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { name: "already verified", // The tx includes invalid data to verify that a cached result is // returned. - tx: &IncreaseBalanceTx{ + tx: &IncreaseL1ValidatorBalanceTx{ BaseTx: BaseTx{ SyntacticallyVerified: true, }, @@ -350,7 +350,7 @@ func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { }, { name: "zero balance", - tx: &IncreaseBalanceTx{ + tx: &IncreaseL1ValidatorBalanceTx{ BaseTx: validBaseTx, Balance: 0, }, @@ -358,7 +358,7 @@ func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { }, { name: "invalid BaseTx", - tx: &IncreaseBalanceTx{ + tx: &IncreaseL1ValidatorBalanceTx{ BaseTx: BaseTx{}, Balance: 1, }, @@ -366,7 +366,7 @@ func TestIncreaseBalanceTxSyntacticVerify(t *testing.T) { }, { name: "passes verification", - tx: &IncreaseBalanceTx{ + tx: &IncreaseL1ValidatorBalanceTx{ BaseTx: validBaseTx, Balance: 1, }, diff --git a/vms/platformvm/txs/increase_balance_tx_test.json b/vms/platformvm/txs/increase_l1_validator_balance_tx_test.json similarity index 100% rename from vms/platformvm/txs/increase_balance_tx_test.json rename to vms/platformvm/txs/increase_l1_validator_balance_tx_test.json diff --git a/vms/platformvm/txs/register_subnet_validator_tx.go b/vms/platformvm/txs/register_l1_validator_tx.go similarity index 73% rename from vms/platformvm/txs/register_subnet_validator_tx.go rename to vms/platformvm/txs/register_l1_validator_tx.go index a5a7a0192329..26120e18532a 100644 --- a/vms/platformvm/txs/register_subnet_validator_tx.go +++ b/vms/platformvm/txs/register_l1_validator_tx.go @@ -9,9 +9,9 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -var _ UnsignedTx = (*RegisterSubnetValidatorTx)(nil) +var _ UnsignedTx = (*RegisterL1ValidatorTx)(nil) -type RegisterSubnetValidatorTx struct { +type RegisterL1ValidatorTx struct { // Metadata, inputs and outputs BaseTx `serialize:"true"` // Balance <= sum($AVAX inputs) - sum($AVAX outputs) - TxFee. @@ -19,11 +19,11 @@ type RegisterSubnetValidatorTx struct { // ProofOfPossession of the BLS key that is included in the Message. ProofOfPossession [bls.SignatureLen]byte `serialize:"true" json:"proofOfPossession"` // Message is expected to be a signed Warp message containing an - // AddressedCall payload with the RegisterSubnetValidator message. + // AddressedCall payload with the RegisterL1Validator message. Message types.JSONByteSlice `serialize:"true" json:"message"` } -func (tx *RegisterSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error { +func (tx *RegisterL1ValidatorTx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: return ErrNilTx @@ -40,6 +40,6 @@ func (tx *RegisterSubnetValidatorTx) SyntacticVerify(ctx *snow.Context) error { return nil } -func (tx *RegisterSubnetValidatorTx) Visit(visitor Visitor) error { - return visitor.RegisterSubnetValidatorTx(tx) +func (tx *RegisterL1ValidatorTx) Visit(visitor Visitor) error { + return visitor.RegisterL1ValidatorTx(tx) } diff --git a/vms/platformvm/txs/register_subnet_validator_tx_test.go b/vms/platformvm/txs/register_l1_validator_tx_test.go similarity index 95% rename from vms/platformvm/txs/register_subnet_validator_tx_test.go rename to vms/platformvm/txs/register_l1_validator_tx_test.go index 64055b6171e0..d1751d1c9061 100644 --- a/vms/platformvm/txs/register_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/register_l1_validator_tx_test.go @@ -25,10 +25,10 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -//go:embed register_subnet_validator_tx_test.json -var registerSubnetValidatorTxJSON []byte +//go:embed register_l1_validator_tx_test.json +var registerL1ValidatorTxJSON []byte -func TestRegisterSubnetValidatorTxSerialization(t *testing.T) { +func TestRegisterL1ValidatorTxSerialization(t *testing.T) { require := require.New(t) const balance = units.Avax @@ -66,7 +66,7 @@ func TestRegisterSubnetValidatorTxSerialization(t *testing.T) { } ) - var unsignedTx UnsignedTx = &RegisterSubnetValidatorTx{ + var unsignedTx UnsignedTx = &RegisterL1ValidatorTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -170,7 +170,7 @@ func TestRegisterSubnetValidatorTxSerialization(t *testing.T) { expectedBytes := []byte{ // Codec version 0x00, 0x00, - // RegisterSubnetValidatorTx Type ID + // RegisterL1ValidatorTx Type ID 0x00, 0x00, 0x00, 0x24, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -329,16 +329,16 @@ func TestRegisterSubnetValidatorTxSerialization(t *testing.T) { require.NoError(err) require.Equal( // Normalize newlines for Windows - strings.ReplaceAll(string(registerSubnetValidatorTxJSON), "\r\n", "\n"), + strings.ReplaceAll(string(registerL1ValidatorTxJSON), "\r\n", "\n"), string(txJSON), ) } -func TestRegisterSubnetValidatorTxSyntacticVerify(t *testing.T) { +func TestRegisterL1ValidatorTxSyntacticVerify(t *testing.T) { ctx := snowtest.Context(t, ids.GenerateTestID()) tests := []struct { name string - tx *RegisterSubnetValidatorTx + tx *RegisterL1ValidatorTx expectedErr error }{ { @@ -350,7 +350,7 @@ func TestRegisterSubnetValidatorTxSyntacticVerify(t *testing.T) { name: "already verified", // The tx includes invalid data to verify that a cached result is // returned. - tx: &RegisterSubnetValidatorTx{ + tx: &RegisterL1ValidatorTx{ BaseTx: BaseTx{ SyntacticallyVerified: true, }, @@ -359,14 +359,14 @@ func TestRegisterSubnetValidatorTxSyntacticVerify(t *testing.T) { }, { name: "invalid BaseTx", - tx: &RegisterSubnetValidatorTx{ + tx: &RegisterL1ValidatorTx{ BaseTx: BaseTx{}, }, expectedErr: avax.ErrWrongNetworkID, }, { name: "passes verification", - tx: &RegisterSubnetValidatorTx{ + tx: &RegisterL1ValidatorTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, diff --git a/vms/platformvm/txs/register_subnet_validator_tx_test.json b/vms/platformvm/txs/register_l1_validator_tx_test.json similarity index 100% rename from vms/platformvm/txs/register_subnet_validator_tx_test.json rename to vms/platformvm/txs/register_l1_validator_tx_test.json diff --git a/vms/platformvm/txs/set_subnet_validator_weight_tx.go b/vms/platformvm/txs/set_l1_validator_weight_tx.go similarity index 65% rename from vms/platformvm/txs/set_subnet_validator_weight_tx.go rename to vms/platformvm/txs/set_l1_validator_weight_tx.go index 519e0bd3bd97..70010aa93fae 100644 --- a/vms/platformvm/txs/set_subnet_validator_weight_tx.go +++ b/vms/platformvm/txs/set_l1_validator_weight_tx.go @@ -8,17 +8,17 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -var _ UnsignedTx = (*SetSubnetValidatorWeightTx)(nil) +var _ UnsignedTx = (*SetL1ValidatorWeightTx)(nil) -type SetSubnetValidatorWeightTx struct { +type SetL1ValidatorWeightTx struct { // Metadata, inputs and outputs BaseTx `serialize:"true"` // Message is expected to be a signed Warp message containing an - // AddressedCall payload with the SetSubnetValidatorWeight message. + // AddressedCall payload with the SetL1ValidatorWeight message. Message types.JSONByteSlice `serialize:"true" json:"message"` } -func (tx *SetSubnetValidatorWeightTx) SyntacticVerify(ctx *snow.Context) error { +func (tx *SetL1ValidatorWeightTx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: return ErrNilTx @@ -35,6 +35,6 @@ func (tx *SetSubnetValidatorWeightTx) SyntacticVerify(ctx *snow.Context) error { return nil } -func (tx *SetSubnetValidatorWeightTx) Visit(visitor Visitor) error { - return visitor.SetSubnetValidatorWeightTx(tx) +func (tx *SetL1ValidatorWeightTx) Visit(visitor Visitor) error { + return visitor.SetL1ValidatorWeightTx(tx) } diff --git a/vms/platformvm/txs/set_subnet_validator_weight_tx_test.go b/vms/platformvm/txs/set_l1_validator_weight_tx_test.go similarity index 94% rename from vms/platformvm/txs/set_subnet_validator_weight_tx_test.go rename to vms/platformvm/txs/set_l1_validator_weight_tx_test.go index 13dd4afc7766..54bd1e979871 100644 --- a/vms/platformvm/txs/set_subnet_validator_weight_tx_test.go +++ b/vms/platformvm/txs/set_l1_validator_weight_tx_test.go @@ -22,10 +22,10 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -//go:embed set_subnet_validator_weight_tx_test.json -var setSubnetValidatorWeightTxJSON []byte +//go:embed set_l1_validator_weight_tx_test.json +var setL1ValidatorWeightTxJSON []byte -func TestSetSubnetValidatorWeightTxSerialization(t *testing.T) { +func TestSetL1ValidatorWeightTxSerialization(t *testing.T) { require := require.New(t) var ( @@ -55,7 +55,7 @@ func TestSetSubnetValidatorWeightTxSerialization(t *testing.T) { } ) - var unsignedTx UnsignedTx = &SetSubnetValidatorWeightTx{ + var unsignedTx UnsignedTx = &SetL1ValidatorWeightTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: constants.UnitTestID, @@ -157,7 +157,7 @@ func TestSetSubnetValidatorWeightTxSerialization(t *testing.T) { expectedBytes := []byte{ // Codec version 0x00, 0x00, - // SetSubnetValidatorWeightTx Type ID + // SetL1ValidatorWeightTx Type ID 0x00, 0x00, 0x00, 0x25, // Network ID 0x00, 0x00, 0x00, 0x0a, @@ -301,16 +301,16 @@ func TestSetSubnetValidatorWeightTxSerialization(t *testing.T) { require.NoError(err) require.Equal( // Normalize newlines for Windows - strings.ReplaceAll(string(setSubnetValidatorWeightTxJSON), "\r\n", "\n"), + strings.ReplaceAll(string(setL1ValidatorWeightTxJSON), "\r\n", "\n"), string(txJSON), ) } -func TestSetSubnetValidatorWeightTxSyntacticVerify(t *testing.T) { +func TestSetL1ValidatorWeightTxSyntacticVerify(t *testing.T) { ctx := snowtest.Context(t, ids.GenerateTestID()) tests := []struct { name string - tx *SetSubnetValidatorWeightTx + tx *SetL1ValidatorWeightTx expectedErr error }{ { @@ -322,7 +322,7 @@ func TestSetSubnetValidatorWeightTxSyntacticVerify(t *testing.T) { name: "already verified", // The tx includes invalid data to verify that a cached result is // returned. - tx: &SetSubnetValidatorWeightTx{ + tx: &SetL1ValidatorWeightTx{ BaseTx: BaseTx{ SyntacticallyVerified: true, }, @@ -331,14 +331,14 @@ func TestSetSubnetValidatorWeightTxSyntacticVerify(t *testing.T) { }, { name: "invalid BaseTx", - tx: &SetSubnetValidatorWeightTx{ + tx: &SetL1ValidatorWeightTx{ BaseTx: BaseTx{}, }, expectedErr: avax.ErrWrongNetworkID, }, { name: "passes verification", - tx: &SetSubnetValidatorWeightTx{ + tx: &SetL1ValidatorWeightTx{ BaseTx: BaseTx{ BaseTx: avax.BaseTx{ NetworkID: ctx.NetworkID, diff --git a/vms/platformvm/txs/set_subnet_validator_weight_tx_test.json b/vms/platformvm/txs/set_l1_validator_weight_tx_test.json similarity index 100% rename from vms/platformvm/txs/set_subnet_validator_weight_tx_test.json rename to vms/platformvm/txs/set_l1_validator_weight_tx_test.json diff --git a/vms/platformvm/txs/txstest/wallet.go b/vms/platformvm/txs/txstest/wallet.go index 2de042d402ef..b022ca3abcb9 100644 --- a/vms/platformvm/txs/txstest/wallet.go +++ b/vms/platformvm/txs/txstest/wallet.go @@ -83,11 +83,11 @@ func NewWallet( owners[subnetID] = owner } for _, validationID := range validationIDs { - sov, err := state.GetSubnetOnlyValidator(validationID) + l1Validator, err := state.GetL1Validator(validationID) require.NoError(err) var owner message.PChainOwner - _, err = txs.Codec.Unmarshal(sov.DeactivationOwner, &owner) + _, err = txs.Codec.Unmarshal(l1Validator.DeactivationOwner, &owner) require.NoError(err) owners[validationID] = &secp256k1fx.OutputOwners{ Threshold: owner.Threshold, diff --git a/vms/platformvm/txs/visitor.go b/vms/platformvm/txs/visitor.go index dead3500dcb2..10705879a2ef 100644 --- a/vms/platformvm/txs/visitor.go +++ b/vms/platformvm/txs/visitor.go @@ -27,9 +27,9 @@ type Visitor interface { BaseTx(*BaseTx) error // Etna Transactions: - ConvertSubnetTx(*ConvertSubnetTx) error - RegisterSubnetValidatorTx(*RegisterSubnetValidatorTx) error - SetSubnetValidatorWeightTx(*SetSubnetValidatorWeightTx) error - IncreaseBalanceTx(*IncreaseBalanceTx) error - DisableSubnetValidatorTx(*DisableSubnetValidatorTx) error + ConvertSubnetToL1Tx(*ConvertSubnetToL1Tx) error + RegisterL1ValidatorTx(*RegisterL1ValidatorTx) error + SetL1ValidatorWeightTx(*SetL1ValidatorWeightTx) error + IncreaseL1ValidatorBalanceTx(*IncreaseL1ValidatorBalanceTx) error + DisableL1ValidatorTx(*DisableL1ValidatorTx) error } diff --git a/vms/platformvm/warp/message/codec.go b/vms/platformvm/warp/message/codec.go index 4dda85a1c76e..8005f1bf2568 100644 --- a/vms/platformvm/warp/message/codec.go +++ b/vms/platformvm/warp/message/codec.go @@ -20,10 +20,10 @@ func init() { lc := linearcodec.NewDefault() err := errors.Join( - lc.RegisterType(&SubnetConversion{}), - lc.RegisterType(&RegisterSubnetValidator{}), - lc.RegisterType(&SubnetValidatorRegistration{}), - lc.RegisterType(&SubnetValidatorWeight{}), + lc.RegisterType(&SubnetToL1Conversion{}), + lc.RegisterType(&RegisterL1Validator{}), + lc.RegisterType(&L1ValidatorRegistration{}), + lc.RegisterType(&L1ValidatorWeight{}), Codec.RegisterCodec(CodecVersion, lc), ) if err != nil { diff --git a/vms/platformvm/warp/message/subnet_validator_registration.go b/vms/platformvm/warp/message/l1_validator_registration.go similarity index 60% rename from vms/platformvm/warp/message/subnet_validator_registration.go rename to vms/platformvm/warp/message/l1_validator_registration.go index f0e1919b1e24..a8bb559ab42b 100644 --- a/vms/platformvm/warp/message/subnet_validator_registration.go +++ b/vms/platformvm/warp/message/l1_validator_registration.go @@ -9,9 +9,8 @@ import ( "github.com/ava-labs/avalanchego/ids" ) -// SubnetValidatorRegistration reports if a validator is registered on the -// P-chain. -type SubnetValidatorRegistration struct { +// L1ValidatorRegistration reports if a validator is registered on the P-chain. +type L1ValidatorRegistration struct { payload ValidationID ids.ID `serialize:"true" json:"validationID"` @@ -24,27 +23,26 @@ type SubnetValidatorRegistration struct { Registered bool `serialize:"true" json:"registered"` } -// NewSubnetValidatorRegistration creates a new initialized -// SubnetValidatorRegistration. -func NewSubnetValidatorRegistration( +// NewL1ValidatorRegistration creates a new initialized L1ValidatorRegistration. +func NewL1ValidatorRegistration( validationID ids.ID, registered bool, -) (*SubnetValidatorRegistration, error) { - msg := &SubnetValidatorRegistration{ +) (*L1ValidatorRegistration, error) { + msg := &L1ValidatorRegistration{ ValidationID: validationID, Registered: registered, } return msg, Initialize(msg) } -// ParseSubnetValidatorRegistration parses bytes into an initialized -// SubnetValidatorRegistration. -func ParseSubnetValidatorRegistration(b []byte) (*SubnetValidatorRegistration, error) { +// ParseL1ValidatorRegistration parses bytes into an initialized +// L1ValidatorRegistration. +func ParseL1ValidatorRegistration(b []byte) (*L1ValidatorRegistration, error) { payloadIntf, err := Parse(b) if err != nil { return nil, err } - payload, ok := payloadIntf.(*SubnetValidatorRegistration) + payload, ok := payloadIntf.(*L1ValidatorRegistration) if !ok { return nil, fmt.Errorf("%w: %T", ErrWrongType, payloadIntf) } diff --git a/vms/platformvm/warp/message/subnet_validator_registration_test.go b/vms/platformvm/warp/message/l1_validator_registration_test.go similarity index 76% rename from vms/platformvm/warp/message/subnet_validator_registration_test.go rename to vms/platformvm/warp/message/l1_validator_registration_test.go index f32a8c80953e..2514c0d841dc 100644 --- a/vms/platformvm/warp/message/subnet_validator_registration_test.go +++ b/vms/platformvm/warp/message/l1_validator_registration_test.go @@ -12,19 +12,19 @@ import ( "github.com/ava-labs/avalanchego/ids" ) -func TestSubnetValidatorRegistration(t *testing.T) { +func TestL1ValidatorRegistration(t *testing.T) { booleans := []bool{true, false} for _, registered := range booleans { t.Run(strconv.FormatBool(registered), func(t *testing.T) { require := require.New(t) - msg, err := NewSubnetValidatorRegistration( + msg, err := NewL1ValidatorRegistration( ids.GenerateTestID(), registered, ) require.NoError(err) - parsed, err := ParseSubnetValidatorRegistration(msg.Bytes()) + parsed, err := ParseL1ValidatorRegistration(msg.Bytes()) require.NoError(err) require.Equal(msg, parsed) }) diff --git a/vms/platformvm/warp/message/subnet_validator_weight.go b/vms/platformvm/warp/message/l1_validator_weight.go similarity index 67% rename from vms/platformvm/warp/message/subnet_validator_weight.go rename to vms/platformvm/warp/message/l1_validator_weight.go index 5b94889a8f03..489df2b18ad7 100644 --- a/vms/platformvm/warp/message/subnet_validator_weight.go +++ b/vms/platformvm/warp/message/l1_validator_weight.go @@ -13,14 +13,14 @@ import ( var ErrNonceReservedForRemoval = errors.New("maxUint64 nonce is reserved for removal") -// SubnetValidatorWeight is both received and sent by the P-chain. +// L1ValidatorWeight is both received and sent by the P-chain. // // If the P-chain is receiving this message, it is treated as a command to // update the weight of the validator. // // If the P-chain is sending this message, it is reporting the current nonce and // weight of the validator. -type SubnetValidatorWeight struct { +type L1ValidatorWeight struct { payload ValidationID ids.ID `serialize:"true" json:"validationID"` @@ -28,20 +28,20 @@ type SubnetValidatorWeight struct { Weight uint64 `serialize:"true" json:"weight"` } -func (s *SubnetValidatorWeight) Verify() error { +func (s *L1ValidatorWeight) Verify() error { if s.Nonce == math.MaxUint64 && s.Weight != 0 { return ErrNonceReservedForRemoval } return nil } -// NewSubnetValidatorWeight creates a new initialized SubnetValidatorWeight. -func NewSubnetValidatorWeight( +// NewL1ValidatorWeight creates a new initialized L1ValidatorWeight. +func NewL1ValidatorWeight( validationID ids.ID, nonce uint64, weight uint64, -) (*SubnetValidatorWeight, error) { - msg := &SubnetValidatorWeight{ +) (*L1ValidatorWeight, error) { + msg := &L1ValidatorWeight{ ValidationID: validationID, Nonce: nonce, Weight: weight, @@ -49,14 +49,13 @@ func NewSubnetValidatorWeight( return msg, Initialize(msg) } -// ParseSubnetValidatorWeight parses bytes into an initialized -// SubnetValidatorWeight. -func ParseSubnetValidatorWeight(b []byte) (*SubnetValidatorWeight, error) { +// ParseL1ValidatorWeight parses bytes into an initialized L1ValidatorWeight. +func ParseL1ValidatorWeight(b []byte) (*L1ValidatorWeight, error) { payloadIntf, err := Parse(b) if err != nil { return nil, err } - payload, ok := payloadIntf.(*SubnetValidatorWeight) + payload, ok := payloadIntf.(*L1ValidatorWeight) if !ok { return nil, fmt.Errorf("%w: %T", ErrWrongType, payloadIntf) } diff --git a/vms/platformvm/warp/message/subnet_validator_weight_test.go b/vms/platformvm/warp/message/l1_validator_weight_test.go similarity index 69% rename from vms/platformvm/warp/message/subnet_validator_weight_test.go rename to vms/platformvm/warp/message/l1_validator_weight_test.go index 17cef30b88cb..e1a3e506e9b7 100644 --- a/vms/platformvm/warp/message/subnet_validator_weight_test.go +++ b/vms/platformvm/warp/message/l1_validator_weight_test.go @@ -13,34 +13,34 @@ import ( "github.com/ava-labs/avalanchego/ids" ) -func TestSubnetValidatorWeight(t *testing.T) { +func TestL1ValidatorWeight(t *testing.T) { require := require.New(t) - msg, err := NewSubnetValidatorWeight( + msg, err := NewL1ValidatorWeight( ids.GenerateTestID(), rand.Uint64(), //#nosec G404 rand.Uint64(), //#nosec G404 ) require.NoError(err) - parsed, err := ParseSubnetValidatorWeight(msg.Bytes()) + parsed, err := ParseL1ValidatorWeight(msg.Bytes()) require.NoError(err) require.Equal(msg, parsed) } -func TestSubnetValidatorWeight_Verify(t *testing.T) { - mustCreate := func(msg *SubnetValidatorWeight, err error) *SubnetValidatorWeight { +func TestL1ValidatorWeight_Verify(t *testing.T) { + mustCreate := func(msg *L1ValidatorWeight, err error) *L1ValidatorWeight { require.NoError(t, err) return msg } tests := []struct { name string - msg *SubnetValidatorWeight + msg *L1ValidatorWeight expected error }{ { name: "Invalid Nonce", - msg: mustCreate(NewSubnetValidatorWeight( + msg: mustCreate(NewL1ValidatorWeight( ids.GenerateTestID(), math.MaxUint64, 1, @@ -49,7 +49,7 @@ func TestSubnetValidatorWeight_Verify(t *testing.T) { }, { name: "Valid", - msg: mustCreate(NewSubnetValidatorWeight( + msg: mustCreate(NewL1ValidatorWeight( ids.GenerateTestID(), math.MaxUint64, 0, diff --git a/vms/platformvm/warp/message/payload_test.go b/vms/platformvm/warp/message/payload_test.go index dc2013f34826..e7ca3312f071 100644 --- a/vms/platformvm/warp/message/payload_test.go +++ b/vms/platformvm/warp/message/payload_test.go @@ -30,11 +30,11 @@ func TestParse(t *testing.T) { expectedErr: codec.ErrUnknownVersion, }, { - name: "SubnetConversion", + name: "SubnetToL1Conversion", bytes: []byte{ // Codec version: 0x00, 0x00, - // Payload type = SubnetConversion: + // Payload type = SubnetToL1Conversion: 0x00, 0x00, 0x00, 0x00, // ID: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -42,7 +42,7 @@ func TestParse(t *testing.T) { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, }, - expected: mustCreate(NewSubnetConversion( + expected: mustCreate(NewSubnetToL1Conversion( ids.ID{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, @@ -52,11 +52,11 @@ func TestParse(t *testing.T) { )), }, { - name: "RegisterSubnetValidator", + name: "RegisterL1Validator", bytes: []byte{ // Codec version: 0x00, 0x00, - // Payload type = RegisterSubnetValidator: + // Payload type = RegisterL1Validator: 0x00, 0x00, 0x00, 0x01, // SubnetID: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -97,7 +97,7 @@ func TestParse(t *testing.T) { // Weight: 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, }, - expected: mustCreate(NewRegisterSubnetValidator( + expected: mustCreate(NewRegisterL1Validator( ids.ID{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, @@ -142,11 +142,11 @@ func TestParse(t *testing.T) { )), }, { - name: "SubnetValidatorRegistration", + name: "L1ValidatorRegistration", bytes: []byte{ // Codec version: 0x00, 0x00, - // Payload type = SubnetValidatorRegistration: + // Payload type = L1ValidatorRegistration: 0x00, 0x00, 0x00, 0x02, // ValidationID: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -156,7 +156,7 @@ func TestParse(t *testing.T) { // Registered: 0x00, }, - expected: mustCreate(NewSubnetValidatorRegistration( + expected: mustCreate(NewL1ValidatorRegistration( ids.ID{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, @@ -167,11 +167,11 @@ func TestParse(t *testing.T) { )), }, { - name: "SubnetValidatorWeight", + name: "L1ValidatorWeight", bytes: []byte{ // Codec version: 0x00, 0x00, - // Payload type = SubnetValidatorWeight: + // Payload type = L1ValidatorWeight: 0x00, 0x00, 0x00, 0x03, // ValidationID: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -183,7 +183,7 @@ func TestParse(t *testing.T) { // Weight: 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, }, - expected: mustCreate(NewSubnetValidatorWeight( + expected: mustCreate(NewL1ValidatorWeight( ids.ID{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, diff --git a/vms/platformvm/warp/message/register_subnet_validator.go b/vms/platformvm/warp/message/register_l1_validator.go similarity index 83% rename from vms/platformvm/warp/message/register_subnet_validator.go rename to vms/platformvm/warp/message/register_l1_validator.go index ba4eb3aab168..3137c5a7df69 100644 --- a/vms/platformvm/warp/message/register_subnet_validator.go +++ b/vms/platformvm/warp/message/register_l1_validator.go @@ -31,8 +31,8 @@ type PChainOwner struct { Addresses []ids.ShortID `serialize:"true" json:"addresses"` } -// RegisterSubnetValidator adds a validator to the subnet. -type RegisterSubnetValidator struct { +// RegisterL1Validator adds a validator to the subnet. +type RegisterL1Validator struct { payload SubnetID ids.ID `serialize:"true" json:"subnetID"` @@ -44,7 +44,7 @@ type RegisterSubnetValidator struct { Weight uint64 `serialize:"true" json:"weight"` } -func (r *RegisterSubnetValidator) Verify() error { +func (r *RegisterL1Validator) Verify() error { if r.SubnetID == constants.PrimaryNetworkID { return ErrInvalidSubnetID } @@ -76,12 +76,12 @@ func (r *RegisterSubnetValidator) Verify() error { return nil } -func (r *RegisterSubnetValidator) ValidationID() ids.ID { +func (r *RegisterL1Validator) ValidationID() ids.ID { return hashing.ComputeHash256Array(r.Bytes()) } -// NewRegisterSubnetValidator creates a new initialized RegisterSubnetValidator. -func NewRegisterSubnetValidator( +// NewRegisterL1Validator creates a new initialized RegisterL1Validator. +func NewRegisterL1Validator( subnetID ids.ID, nodeID ids.NodeID, blsPublicKey [bls.PublicKeyLen]byte, @@ -89,8 +89,8 @@ func NewRegisterSubnetValidator( remainingBalanceOwner PChainOwner, disableOwner PChainOwner, weight uint64, -) (*RegisterSubnetValidator, error) { - msg := &RegisterSubnetValidator{ +) (*RegisterL1Validator, error) { + msg := &RegisterL1Validator{ SubnetID: subnetID, NodeID: nodeID[:], BLSPublicKey: blsPublicKey, @@ -102,14 +102,14 @@ func NewRegisterSubnetValidator( return msg, Initialize(msg) } -// ParseRegisterSubnetValidator parses bytes into an initialized -// RegisterSubnetValidator. -func ParseRegisterSubnetValidator(b []byte) (*RegisterSubnetValidator, error) { +// ParseRegisterL1Validator parses bytes into an initialized +// RegisterL1Validator. +func ParseRegisterL1Validator(b []byte) (*RegisterL1Validator, error) { payloadIntf, err := Parse(b) if err != nil { return nil, err } - payload, ok := payloadIntf.(*RegisterSubnetValidator) + payload, ok := payloadIntf.(*RegisterL1Validator) if !ok { return nil, fmt.Errorf("%w: %T", ErrWrongType, payloadIntf) } diff --git a/vms/platformvm/warp/message/register_subnet_validator_test.go b/vms/platformvm/warp/message/register_l1_validator_test.go similarity index 86% rename from vms/platformvm/warp/message/register_subnet_validator_test.go rename to vms/platformvm/warp/message/register_l1_validator_test.go index 68898e47979f..23c00c4ef4f5 100644 --- a/vms/platformvm/warp/message/register_subnet_validator_test.go +++ b/vms/platformvm/warp/message/register_l1_validator_test.go @@ -24,10 +24,10 @@ func newBLSPublicKey(t *testing.T) [bls.PublicKeyLen]byte { return [bls.PublicKeyLen]byte(pkBytes) } -func TestRegisterSubnetValidator(t *testing.T) { +func TestRegisterL1Validator(t *testing.T) { require := require.New(t) - msg, err := NewRegisterSubnetValidator( + msg, err := NewRegisterL1Validator( ids.GenerateTestID(), ids.GenerateTestNodeID(), newBLSPublicKey(t), @@ -52,24 +52,24 @@ func TestRegisterSubnetValidator(t *testing.T) { var expectedValidationID ids.ID = hashing.ComputeHash256Array(bytes) require.Equal(expectedValidationID, msg.ValidationID()) - parsed, err := ParseRegisterSubnetValidator(bytes) + parsed, err := ParseRegisterL1Validator(bytes) require.NoError(err) require.Equal(msg, parsed) } -func TestRegisterSubnetValidator_Verify(t *testing.T) { - mustCreate := func(msg *RegisterSubnetValidator, err error) *RegisterSubnetValidator { +func TestRegisterL1Validator_Verify(t *testing.T) { + mustCreate := func(msg *RegisterL1Validator, err error) *RegisterL1Validator { require.NoError(t, err) return msg } tests := []struct { name string - msg *RegisterSubnetValidator + msg *RegisterL1Validator expected error }{ { name: "PrimaryNetworkID", - msg: mustCreate(NewRegisterSubnetValidator( + msg: mustCreate(NewRegisterL1Validator( constants.PrimaryNetworkID, ids.GenerateTestNodeID(), newBLSPublicKey(t), @@ -89,7 +89,7 @@ func TestRegisterSubnetValidator_Verify(t *testing.T) { }, { name: "Weight = 0", - msg: mustCreate(NewRegisterSubnetValidator( + msg: mustCreate(NewRegisterL1Validator( ids.GenerateTestID(), ids.GenerateTestNodeID(), newBLSPublicKey(t), @@ -109,7 +109,7 @@ func TestRegisterSubnetValidator_Verify(t *testing.T) { }, { name: "Invalid NodeID Length", - msg: &RegisterSubnetValidator{ + msg: &RegisterL1Validator{ SubnetID: ids.GenerateTestID(), NodeID: nil, BLSPublicKey: newBLSPublicKey(t), @@ -129,7 +129,7 @@ func TestRegisterSubnetValidator_Verify(t *testing.T) { }, { name: "Invalid NodeID", - msg: mustCreate(NewRegisterSubnetValidator( + msg: mustCreate(NewRegisterL1Validator( ids.GenerateTestID(), ids.EmptyNodeID, newBLSPublicKey(t), @@ -149,7 +149,7 @@ func TestRegisterSubnetValidator_Verify(t *testing.T) { }, { name: "Invalid Owner", - msg: mustCreate(NewRegisterSubnetValidator( + msg: mustCreate(NewRegisterL1Validator( ids.GenerateTestID(), ids.GenerateTestNodeID(), newBLSPublicKey(t), @@ -169,7 +169,7 @@ func TestRegisterSubnetValidator_Verify(t *testing.T) { }, { name: "Valid", - msg: mustCreate(NewRegisterSubnetValidator( + msg: mustCreate(NewRegisterL1Validator( ids.GenerateTestID(), ids.GenerateTestNodeID(), newBLSPublicKey(t), diff --git a/vms/platformvm/warp/message/subnet_conversion.go b/vms/platformvm/warp/message/subnet_conversion.go deleted file mode 100644 index f1af8e78e5ab..000000000000 --- a/vms/platformvm/warp/message/subnet_conversion.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package message - -import ( - "fmt" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/hashing" - "github.com/ava-labs/avalanchego/vms/types" -) - -type SubnetConversionValidatorData struct { - NodeID types.JSONByteSlice `serialize:"true" json:"nodeID"` - BLSPublicKey [bls.PublicKeyLen]byte `serialize:"true" json:"blsPublicKey"` - Weight uint64 `serialize:"true" json:"weight"` -} - -type SubnetConversionData struct { - SubnetID ids.ID `serialize:"true" json:"subnetID"` - ManagerChainID ids.ID `serialize:"true" json:"managerChainID"` - ManagerAddress types.JSONByteSlice `serialize:"true" json:"managerAddress"` - Validators []SubnetConversionValidatorData `serialize:"true" json:"validators"` -} - -// SubnetConversionID creates a subnet conversion ID from the provided subnet -// conversion data. -func SubnetConversionID(data SubnetConversionData) (ids.ID, error) { - bytes, err := Codec.Marshal(CodecVersion, &data) - if err != nil { - return ids.Empty, err - } - return hashing.ComputeHash256Array(bytes), nil -} - -// SubnetConversion reports the summary of the subnet conversation that occurred -// on the P-chain. -type SubnetConversion struct { - payload - - // ID of the subnet conversion. It is typically generated by calling - // SubnetConversionID. - ID ids.ID `serialize:"true" json:"id"` -} - -// NewSubnetConversion creates a new initialized SubnetConversion. -func NewSubnetConversion(id ids.ID) (*SubnetConversion, error) { - msg := &SubnetConversion{ - ID: id, - } - return msg, Initialize(msg) -} - -// ParseSubnetConversion parses bytes into an initialized SubnetConversion. -func ParseSubnetConversion(b []byte) (*SubnetConversion, error) { - payloadIntf, err := Parse(b) - if err != nil { - return nil, err - } - payload, ok := payloadIntf.(*SubnetConversion) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrWrongType, payloadIntf) - } - return payload, nil -} diff --git a/vms/platformvm/warp/message/subnet_to_l1_conversion.go b/vms/platformvm/warp/message/subnet_to_l1_conversion.go new file mode 100644 index 000000000000..670076ce4f1b --- /dev/null +++ b/vms/platformvm/warp/message/subnet_to_l1_conversion.go @@ -0,0 +1,68 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package message + +import ( + "fmt" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/hashing" + "github.com/ava-labs/avalanchego/vms/types" +) + +type SubnetToL1ConverstionValidatorData struct { + NodeID types.JSONByteSlice `serialize:"true" json:"nodeID"` + BLSPublicKey [bls.PublicKeyLen]byte `serialize:"true" json:"blsPublicKey"` + Weight uint64 `serialize:"true" json:"weight"` +} + +type SubnetToL1ConversionData struct { + SubnetID ids.ID `serialize:"true" json:"subnetID"` + ManagerChainID ids.ID `serialize:"true" json:"managerChainID"` + ManagerAddress types.JSONByteSlice `serialize:"true" json:"managerAddress"` + Validators []SubnetToL1ConverstionValidatorData `serialize:"true" json:"validators"` +} + +// SubnetToL1ConversionID creates a subnet conversion ID from the provided +// subnet conversion data. +func SubnetToL1ConversionID(data SubnetToL1ConversionData) (ids.ID, error) { + bytes, err := Codec.Marshal(CodecVersion, &data) + if err != nil { + return ids.Empty, err + } + return hashing.ComputeHash256Array(bytes), nil +} + +// SubnetToL1Conversion reports the summary of the subnet conversation that +// occurred on the P-chain. +type SubnetToL1Conversion struct { + payload + + // ID of the subnet conversion. It is typically generated by calling + // SubnetToL1ConversionID. + ID ids.ID `serialize:"true" json:"id"` +} + +// NewSubnetToL1Conversion creates a new initialized SubnetToL1Conversion. +func NewSubnetToL1Conversion(id ids.ID) (*SubnetToL1Conversion, error) { + msg := &SubnetToL1Conversion{ + ID: id, + } + return msg, Initialize(msg) +} + +// ParseSubnetToL1Conversion parses bytes into an initialized +// SubnetToL1Conversion. +func ParseSubnetToL1Conversion(b []byte) (*SubnetToL1Conversion, error) { + payloadIntf, err := Parse(b) + if err != nil { + return nil, err + } + payload, ok := payloadIntf.(*SubnetToL1Conversion) + if !ok { + return nil, fmt.Errorf("%w: %T", ErrWrongType, payloadIntf) + } + return payload, nil +} diff --git a/vms/platformvm/warp/message/subnet_conversion_test.go b/vms/platformvm/warp/message/subnet_to_l1_conversion_test.go similarity index 82% rename from vms/platformvm/warp/message/subnet_conversion_test.go rename to vms/platformvm/warp/message/subnet_to_l1_conversion_test.go index 1da07f75e344..5084e1bbe73d 100644 --- a/vms/platformvm/warp/message/subnet_conversion_test.go +++ b/vms/platformvm/warp/message/subnet_to_l1_conversion_test.go @@ -14,10 +14,10 @@ import ( "github.com/ava-labs/avalanchego/vms/types" ) -func TestSubnetConversionID(t *testing.T) { +func TestSubnetToL1ConversionID(t *testing.T) { require := require.New(t) - subnetConversionDataBytes := []byte{ + subnetToL1ConversionDataBytes := []byte{ // Codec version: 0x00, 0x00, // SubnetID: @@ -53,9 +53,9 @@ func TestSubnetConversionID(t *testing.T) { // Weight: 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, } - var expectedSubnetConversionID ids.ID = hashing.ComputeHash256Array(subnetConversionDataBytes) + var expectedSubnetToL1ConversionID ids.ID = hashing.ComputeHash256Array(subnetToL1ConversionDataBytes) - subnetConversionData := SubnetConversionData{ + subnetToL1ConversionData := SubnetToL1ConversionData{ SubnetID: ids.ID{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, @@ -69,7 +69,7 @@ func TestSubnetConversionID(t *testing.T) { 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, }, ManagerAddress: []byte{0x41}, - Validators: []SubnetConversionValidatorData{ + Validators: []SubnetToL1ConverstionValidatorData{ { NodeID: types.JSONByteSlice([]byte{ 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, @@ -88,18 +88,18 @@ func TestSubnetConversionID(t *testing.T) { }, }, } - subnetConversionID, err := SubnetConversionID(subnetConversionData) + subnetToL1ConversionID, err := SubnetToL1ConversionID(subnetToL1ConversionData) require.NoError(err) - require.Equal(expectedSubnetConversionID, subnetConversionID) + require.Equal(expectedSubnetToL1ConversionID, subnetToL1ConversionID) } -func TestSubnetConversion(t *testing.T) { +func TestSubnetToL1Conversion(t *testing.T) { require := require.New(t) - msg, err := NewSubnetConversion(ids.GenerateTestID()) + msg, err := NewSubnetToL1Conversion(ids.GenerateTestID()) require.NoError(err) - parsed, err := ParseSubnetConversion(msg.Bytes()) + parsed, err := ParseSubnetToL1Conversion(msg.Bytes()) require.NoError(err) require.Equal(msg, parsed) } diff --git a/wallet/chain/p/builder/builder.go b/wallet/chain/p/builder/builder.go index 46bca0eb8c36..b783e80178ac 100644 --- a/wallet/chain/p/builder/builder.go +++ b/wallet/chain/p/builder/builder.go @@ -151,63 +151,64 @@ type Builder interface { options ...common.Option, ) (*txs.TransferSubnetOwnershipTx, error) - // NewConvertSubnetTx converts the subnet to a Permissionless L1. + // NewConvertSubnetToL1Tx converts the subnet to a Permissionless L1. // // - [subnetID] specifies the subnet to be converted // - [chainID] specifies which chain the manager is deployed on // - [address] specifies the address of the manager - // - [validators] specifies the initial SoVs of the L1 - NewConvertSubnetTx( + // - [validators] specifies the initial L1 validators of the L1 + NewConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, - ) (*txs.ConvertSubnetTx, error) + ) (*txs.ConvertSubnetToL1Tx, error) - // RegisterSubnetValidatorTx adds a validator to an L1. + // RegisterL1ValidatorTx adds a validator to an L1. // // - [balance] that the validator should allocate to continuous fees // - [proofOfPossession] is the BLS PoP for the key included in the Warp // message // - [message] is the Warp message that authorizes this validator to be // added - NewRegisterSubnetValidatorTx( + NewRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, - ) (*txs.RegisterSubnetValidatorTx, error) + ) (*txs.RegisterL1ValidatorTx, error) - // NewSetSubnetValidatorWeightTx sets the weight of a validator on an L1. + // NewSetL1ValidatorWeightTx sets the weight of a validator on an L1. // // - [message] is the Warp message that authorizes this validator's weight // to be changed - NewSetSubnetValidatorWeightTx( + NewSetL1ValidatorWeightTx( message []byte, options ...common.Option, - ) (*txs.SetSubnetValidatorWeightTx, error) + ) (*txs.SetL1ValidatorWeightTx, error) - // NewIncreaseBalanceTx increases the balance of a validator on an L1 for + // NewIncreaseL1ValidatorBalanceTx increases the balance of a validator on + // an L1 for the continuous fee. // the continuous fee. // // - [validationID] of the validator // - [balance] amount to increase the validator's balance by - NewIncreaseBalanceTx( + NewIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, - ) (*txs.IncreaseBalanceTx, error) + ) (*txs.IncreaseL1ValidatorBalanceTx, error) - // NewDisableSubnetValidatorTx disables an L1 validator and returns the + // NewDisableL1ValidatorTx disables an L1 validator and returns the // remaining funds allocated to the continuous fee to the remaining balance // owner. // // - [validationID] of the validator to disable - NewDisableSubnetValidatorTx( + NewDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, - ) (*txs.DisableSubnetValidatorTx, error) + ) (*txs.DisableL1ValidatorTx, error) // NewImportTx creates an import transaction that attempts to consume all // the available UTXOs and import the funds to [to]. @@ -825,13 +826,13 @@ func (b *builder) NewTransferSubnetOwnershipTx( return tx, b.initCtx(tx) } -func (b *builder) NewConvertSubnetTx( +func (b *builder) NewConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, -) (*txs.ConvertSubnetTx, error) { +) (*txs.ConvertSubnetToL1Tx, error) { var avaxToBurn uint64 for _, vdr := range validators { var err error @@ -861,7 +862,7 @@ func (b *builder) NewConvertSubnetTx( bytesComplexity := gas.Dimensions{ gas.Bandwidth: additionalBytes, } - validatorComplexity, err := fee.ConvertSubnetValidatorComplexity(validators...) + validatorComplexity, err := fee.ConvertSubnetToL1ValidatorComplexity(validators...) if err != nil { return nil, err } @@ -869,7 +870,7 @@ func (b *builder) NewConvertSubnetTx( if err != nil { return nil, err } - complexity, err := fee.IntrinsicConvertSubnetTxComplexities.Add( + complexity, err := fee.IntrinsicConvertSubnetToL1TxComplexities.Add( &bytesComplexity, &validatorComplexity, &authComplexity, @@ -891,7 +892,7 @@ func (b *builder) NewConvertSubnetTx( } utils.Sort(validators) - tx := &txs.ConvertSubnetTx{ + tx := &txs.ConvertSubnetToL1Tx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: b.context.NetworkID, BlockchainID: constants.PlatformChainID, @@ -908,12 +909,12 @@ func (b *builder) NewConvertSubnetTx( return tx, b.initCtx(tx) } -func (b *builder) NewRegisterSubnetValidatorTx( +func (b *builder) NewRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, -) (*txs.RegisterSubnetValidatorTx, error) { +) (*txs.RegisterL1ValidatorTx, error) { var ( toBurn = map[ids.ID]uint64{ b.context.AVAXAssetID: balance, @@ -930,7 +931,7 @@ func (b *builder) NewRegisterSubnetValidatorTx( if err != nil { return nil, err } - complexity, err := fee.IntrinsicRegisterSubnetValidatorTxComplexities.Add( + complexity, err := fee.IntrinsicRegisterL1ValidatorTxComplexities.Add( &memoComplexity, &warpComplexity, ) @@ -950,7 +951,7 @@ func (b *builder) NewRegisterSubnetValidatorTx( return nil, err } - tx := &txs.RegisterSubnetValidatorTx{ + tx := &txs.RegisterL1ValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: b.context.NetworkID, BlockchainID: constants.PlatformChainID, @@ -965,10 +966,10 @@ func (b *builder) NewRegisterSubnetValidatorTx( return tx, b.initCtx(tx) } -func (b *builder) NewSetSubnetValidatorWeightTx( +func (b *builder) NewSetL1ValidatorWeightTx( message []byte, options ...common.Option, -) (*txs.SetSubnetValidatorWeightTx, error) { +) (*txs.SetL1ValidatorWeightTx, error) { var ( toBurn = map[ids.ID]uint64{} toStake = map[ids.ID]uint64{} @@ -982,7 +983,7 @@ func (b *builder) NewSetSubnetValidatorWeightTx( if err != nil { return nil, err } - complexity, err := fee.IntrinsicSetSubnetValidatorWeightTxComplexities.Add( + complexity, err := fee.IntrinsicSetL1ValidatorWeightTxComplexities.Add( &memoComplexity, &warpComplexity, ) @@ -1002,7 +1003,7 @@ func (b *builder) NewSetSubnetValidatorWeightTx( return nil, err } - tx := &txs.SetSubnetValidatorWeightTx{ + tx := &txs.SetL1ValidatorWeightTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: b.context.NetworkID, BlockchainID: constants.PlatformChainID, @@ -1015,11 +1016,11 @@ func (b *builder) NewSetSubnetValidatorWeightTx( return tx, b.initCtx(tx) } -func (b *builder) NewIncreaseBalanceTx( +func (b *builder) NewIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, -) (*txs.IncreaseBalanceTx, error) { +) (*txs.IncreaseL1ValidatorBalanceTx, error) { var ( toBurn = map[ids.ID]uint64{ b.context.AVAXAssetID: balance, @@ -1031,7 +1032,7 @@ func (b *builder) NewIncreaseBalanceTx( gas.Bandwidth: uint64(len(memo)), } ) - complexity, err := fee.IntrinsicIncreaseBalanceTxComplexities.Add( + complexity, err := fee.IntrinsicIncreaseL1ValidatorBalanceTxComplexities.Add( &memoComplexity, ) if err != nil { @@ -1050,7 +1051,7 @@ func (b *builder) NewIncreaseBalanceTx( return nil, err } - tx := &txs.IncreaseBalanceTx{ + tx := &txs.IncreaseL1ValidatorBalanceTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: b.context.NetworkID, BlockchainID: constants.PlatformChainID, @@ -1064,10 +1065,10 @@ func (b *builder) NewIncreaseBalanceTx( return tx, b.initCtx(tx) } -func (b *builder) NewDisableSubnetValidatorTx( +func (b *builder) NewDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, -) (*txs.DisableSubnetValidatorTx, error) { +) (*txs.DisableL1ValidatorTx, error) { var ( toBurn = map[ids.ID]uint64{} toStake = map[ids.ID]uint64{} @@ -1087,7 +1088,7 @@ func (b *builder) NewDisableSubnetValidatorTx( return nil, err } - complexity, err := fee.IntrinsicDisableSubnetValidatorTxComplexities.Add( + complexity, err := fee.IntrinsicDisableL1ValidatorTxComplexities.Add( &memoComplexity, &authComplexity, ) @@ -1107,7 +1108,7 @@ func (b *builder) NewDisableSubnetValidatorTx( return nil, err } - tx := &txs.DisableSubnetValidatorTx{ + tx := &txs.DisableL1ValidatorTx{ BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ NetworkID: b.context.NetworkID, BlockchainID: constants.PlatformChainID, diff --git a/wallet/chain/p/builder/with_options.go b/wallet/chain/p/builder/with_options.go index fa51ed0657d0..350d1c76ac99 100644 --- a/wallet/chain/p/builder/with_options.go +++ b/wallet/chain/p/builder/with_options.go @@ -155,14 +155,14 @@ func (w *withOptions) NewTransferSubnetOwnershipTx( ) } -func (w *withOptions) NewConvertSubnetTx( +func (w *withOptions) NewConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, -) (*txs.ConvertSubnetTx, error) { - return w.builder.NewConvertSubnetTx( +) (*txs.ConvertSubnetToL1Tx, error) { + return w.builder.NewConvertSubnetToL1Tx( subnetID, chainID, address, @@ -171,13 +171,13 @@ func (w *withOptions) NewConvertSubnetTx( ) } -func (w *withOptions) NewRegisterSubnetValidatorTx( +func (w *withOptions) NewRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, -) (*txs.RegisterSubnetValidatorTx, error) { - return w.builder.NewRegisterSubnetValidatorTx( +) (*txs.RegisterL1ValidatorTx, error) { + return w.builder.NewRegisterL1ValidatorTx( balance, proofOfPossession, message, @@ -185,33 +185,33 @@ func (w *withOptions) NewRegisterSubnetValidatorTx( ) } -func (w *withOptions) NewSetSubnetValidatorWeightTx( +func (w *withOptions) NewSetL1ValidatorWeightTx( message []byte, options ...common.Option, -) (*txs.SetSubnetValidatorWeightTx, error) { - return w.builder.NewSetSubnetValidatorWeightTx( +) (*txs.SetL1ValidatorWeightTx, error) { + return w.builder.NewSetL1ValidatorWeightTx( message, common.UnionOptions(w.options, options)..., ) } -func (w *withOptions) NewIncreaseBalanceTx( +func (w *withOptions) NewIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, -) (*txs.IncreaseBalanceTx, error) { - return w.builder.NewIncreaseBalanceTx( +) (*txs.IncreaseL1ValidatorBalanceTx, error) { + return w.builder.NewIncreaseL1ValidatorBalanceTx( validationID, balance, common.UnionOptions(w.options, options)..., ) } -func (w *withOptions) NewDisableSubnetValidatorTx( +func (w *withOptions) NewDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, -) (*txs.DisableSubnetValidatorTx, error) { - return w.builder.NewDisableSubnetValidatorTx( +) (*txs.DisableL1ValidatorTx, error) { + return w.builder.NewDisableL1ValidatorTx( validationID, common.UnionOptions(w.options, options)..., ) diff --git a/wallet/chain/p/builder_test.go b/wallet/chain/p/builder_test.go index 77fa6e49ee35..b98e0d30e722 100644 --- a/wallet/chain/p/builder_test.go +++ b/wallet/chain/p/builder_test.go @@ -681,7 +681,7 @@ func TestAddPermissionlessDelegatorTx(t *testing.T) { } } -func TestConvertSubnetTx(t *testing.T) { +func TestConvertSubnetToL1Tx(t *testing.T) { sk0, err := bls.NewSecretKey() require.NoError(t, err) sk1, err := bls.NewSecretKey() @@ -690,7 +690,7 @@ func TestConvertSubnetTx(t *testing.T) { var ( chainID = ids.GenerateTestID() address = utils.RandomBytes(32) - validators = []*txs.ConvertSubnetValidator{ + validators = []*txs.ConvertSubnetToL1Validator{ { NodeID: utils.RandomBytes(ids.NodeIDLen), Weight: rand.Uint64(), //#nosec G404 @@ -730,7 +730,7 @@ func TestConvertSubnetTx(t *testing.T) { builder = builder.New(set.Of(utxoAddr, subnetAuthAddr), e.context, backend) ) - utx, err := builder.NewConvertSubnetTx( + utx, err := builder.NewConvertSubnetToL1Tx( subnetID, chainID, address, @@ -759,7 +759,7 @@ func TestConvertSubnetTx(t *testing.T) { } } -func TestRegisterSubnetValidatorTx(t *testing.T) { +func TestRegisterL1ValidatorTx(t *testing.T) { const ( expiry = 1731005097 weight = 7905001371 @@ -771,7 +771,7 @@ func TestRegisterSubnetValidatorTx(t *testing.T) { require.NoError(t, err) pop := signer.NewProofOfPossession(sk) - addressedCallPayload, err := message.NewRegisterSubnetValidator( + addressedCallPayload, err := message.NewRegisterL1Validator( subnetID, nodeID, pop.PublicKey, @@ -833,7 +833,7 @@ func TestRegisterSubnetValidatorTx(t *testing.T) { builder = builder.New(set.Of(utxoAddr), e.context, backend) ) - utx, err := builder.NewRegisterSubnetValidatorTx( + utx, err := builder.NewRegisterL1ValidatorTx( balance, pop.ProofOfPossession, warpMessageBytes, @@ -859,7 +859,7 @@ func TestRegisterSubnetValidatorTx(t *testing.T) { } } -func TestSetSubnetValidatorWeightTx(t *testing.T) { +func TestSetL1ValidatorWeightTx(t *testing.T) { const ( nonce = 1 weight = 7905001371 @@ -870,7 +870,7 @@ func TestSetSubnetValidatorWeightTx(t *testing.T) { address = utils.RandomBytes(20) ) - addressedCallPayload, err := message.NewSubnetValidatorWeight( + addressedCallPayload, err := message.NewL1ValidatorWeight( validationID, nonce, weight, @@ -921,7 +921,7 @@ func TestSetSubnetValidatorWeightTx(t *testing.T) { builder = builder.New(set.Of(utxoAddr), e.context, backend) ) - utx, err := builder.NewSetSubnetValidatorWeightTx( + utx, err := builder.NewSetL1ValidatorWeightTx( warpMessageBytes, common.WithMemo(e.memo), ) @@ -941,7 +941,7 @@ func TestSetSubnetValidatorWeightTx(t *testing.T) { } } -func TestIncreaseIncreaseBalanceTx(t *testing.T) { +func TestIncreaseL1ValidatorBalanceTx(t *testing.T) { const balance = units.Avax validationID := ids.GenerateTestID() for _, e := range testEnvironmentPostEtna { @@ -955,7 +955,7 @@ func TestIncreaseIncreaseBalanceTx(t *testing.T) { builder = builder.New(set.Of(utxoAddr), e.context, backend) ) - utx, err := builder.NewIncreaseBalanceTx( + utx, err := builder.NewIncreaseL1ValidatorBalanceTx( validationID, balance, common.WithMemo(e.memo), @@ -979,7 +979,7 @@ func TestIncreaseIncreaseBalanceTx(t *testing.T) { } } -func TestDisableSubnetValidatorTx(t *testing.T) { +func TestDisableL1ValidatorTx(t *testing.T) { for _, e := range testEnvironmentPostEtna { t.Run(e.name, func(t *testing.T) { var ( @@ -991,7 +991,7 @@ func TestDisableSubnetValidatorTx(t *testing.T) { builder = builder.New(set.Of(utxoAddr, validationAuthAddr), e.context, backend) ) - utx, err := builder.NewDisableSubnetValidatorTx( + utx, err := builder.NewDisableL1ValidatorTx( validationID, common.WithMemo(e.memo), ) diff --git a/wallet/chain/p/signer/visitor.go b/wallet/chain/p/signer/visitor.go index 7be3ee0ea76c..8552194aa7df 100644 --- a/wallet/chain/p/signer/visitor.go +++ b/wallet/chain/p/signer/visitor.go @@ -185,7 +185,7 @@ func (s *visitor) BaseTx(tx *txs.BaseTx) error { return sign(s.tx, false, txSigners) } -func (s *visitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { +func (s *visitor) ConvertSubnetToL1Tx(tx *txs.ConvertSubnetToL1Tx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { return err @@ -198,7 +198,7 @@ func (s *visitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return sign(s.tx, true, txSigners) } -func (s *visitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) error { +func (s *visitor) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { return err @@ -206,7 +206,7 @@ func (s *visitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) e return sign(s.tx, true, txSigners) } -func (s *visitor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) error { +func (s *visitor) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { return err @@ -214,7 +214,7 @@ func (s *visitor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) return sign(s.tx, true, txSigners) } -func (s *visitor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error { +func (s *visitor) IncreaseL1ValidatorBalanceTx(tx *txs.IncreaseL1ValidatorBalanceTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { return err @@ -222,7 +222,7 @@ func (s *visitor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error { return sign(s.tx, true, txSigners) } -func (s *visitor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValidatorTx) error { +func (s *visitor) DisableL1ValidatorTx(tx *txs.DisableL1ValidatorTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { return err diff --git a/wallet/chain/p/wallet/backend_visitor.go b/wallet/chain/p/wallet/backend_visitor.go index ebab7fae6908..1e8046f2575a 100644 --- a/wallet/chain/p/wallet/backend_visitor.go +++ b/wallet/chain/p/wallet/backend_visitor.go @@ -123,7 +123,7 @@ func (b *backendVisitor) BaseTx(tx *txs.BaseTx) error { return b.baseTx(tx) } -func (b *backendVisitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { +func (b *backendVisitor) ConvertSubnetToL1Tx(tx *txs.ConvertSubnetToL1Tx) error { for i, vdr := range tx.Validators { b.b.setOwner( tx.Subnet.Append(uint32(i)), @@ -136,7 +136,7 @@ func (b *backendVisitor) ConvertSubnetTx(tx *txs.ConvertSubnetTx) error { return b.baseTx(&tx.BaseTx) } -func (b *backendVisitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidatorTx) error { +func (b *backendVisitor) RegisterL1ValidatorTx(tx *txs.RegisterL1ValidatorTx) error { warpMessage, err := warp.ParseMessage(tx.Message) if err != nil { return err @@ -145,30 +145,30 @@ func (b *backendVisitor) RegisterSubnetValidatorTx(tx *txs.RegisterSubnetValidat if err != nil { return err } - registerSubnetValidatorMessage, err := message.ParseRegisterSubnetValidator(addressedCallPayload.Payload) + registerL1ValidatorMessage, err := message.ParseRegisterL1Validator(addressedCallPayload.Payload) if err != nil { return err } b.b.setOwner( - registerSubnetValidatorMessage.ValidationID(), + registerL1ValidatorMessage.ValidationID(), &secp256k1fx.OutputOwners{ - Threshold: registerSubnetValidatorMessage.DisableOwner.Threshold, - Addrs: registerSubnetValidatorMessage.DisableOwner.Addresses, + Threshold: registerL1ValidatorMessage.DisableOwner.Threshold, + Addrs: registerL1ValidatorMessage.DisableOwner.Addresses, }, ) return b.baseTx(&tx.BaseTx) } -func (b *backendVisitor) SetSubnetValidatorWeightTx(tx *txs.SetSubnetValidatorWeightTx) error { +func (b *backendVisitor) SetL1ValidatorWeightTx(tx *txs.SetL1ValidatorWeightTx) error { return b.baseTx(&tx.BaseTx) } -func (b *backendVisitor) IncreaseBalanceTx(tx *txs.IncreaseBalanceTx) error { +func (b *backendVisitor) IncreaseL1ValidatorBalanceTx(tx *txs.IncreaseL1ValidatorBalanceTx) error { return b.baseTx(&tx.BaseTx) } -func (b *backendVisitor) DisableSubnetValidatorTx(tx *txs.DisableSubnetValidatorTx) error { +func (b *backendVisitor) DisableL1ValidatorTx(tx *txs.DisableL1ValidatorTx) error { return b.baseTx(&tx.BaseTx) } diff --git a/wallet/chain/p/wallet/wallet.go b/wallet/chain/p/wallet/wallet.go index ab7d40de08b9..d2f4d7a0f675 100644 --- a/wallet/chain/p/wallet/wallet.go +++ b/wallet/chain/p/wallet/wallet.go @@ -136,63 +136,64 @@ type Wallet interface { options ...common.Option, ) (*txs.Tx, error) - // IssueConvertSubnetTx creates, signs, and issues a transaction that + // IssueConvertSubnetToL1Tx creates, signs, and issues a transaction that // converts the subnet to a Permissionless L1. // // - [subnetID] specifies the subnet to be converted // - [chainID] specifies which chain the manager is deployed on // - [address] specifies the address of the manager - // - [validators] specifies the initial SoVs of the L1 - IssueConvertSubnetTx( + // - [validators] specifies the initial L1 validators of the L1 + IssueConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, ) (*txs.Tx, error) - // IssueRegisterSubnetValidatorTx creates, signs, and issues a transaction - // that adds a validator to an L1. + // IssueRegisterL1ValidatorTx creates, signs, and issues a transaction that + // adds a validator to an L1. // // - [balance] that the validator should allocate to continuous fees // - [proofOfPossession] is the BLS PoP for the key included in the Warp // message // - [message] is the Warp message that authorizes this validator to be // added - IssueRegisterSubnetValidatorTx( + IssueRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, ) (*txs.Tx, error) - // IssueSetSubnetValidatorWeightTx creates, signs, and issues a transaction - // that sets the weight of a validator on an L1. + // IssueSetL1ValidatorWeightTx creates, signs, and issues a transaction that + // sets the weight of a validator on an L1. // // - [message] is the Warp message that authorizes this validator's weight // to be changed - IssueSetSubnetValidatorWeightTx( + IssueSetL1ValidatorWeightTx( message []byte, options ...common.Option, ) (*txs.Tx, error) - // IssueIncreaseBalanceTx creates, signs, and issues a transaction that - // increases the balance of a validator on an L1 for the continuous fee. + // IssueIncreaseL1ValidatorBalanceTx creates, signs, and issues a + // transaction that increases the balance of a validator on an L1 for the + // continuous fee. // // - [validationID] of the validator // - [balance] amount to increase the validator's balance by - IssueIncreaseBalanceTx( + IssueIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, ) (*txs.Tx, error) - // IssueDisableSubnetValidatorTx creates, signs, and issues a transaction - // that disables an L1 validator and returns the remaining funds allocated - // to the continuous fee to the remaining balance owner. + // IssueDisableL1ValidatorTx creates, signs, and issues a transaction that + // disables an L1 validator and returns the remaining funds allocated to the + // continuous fee to the remaining balance owner. // // - [validationID] of the validator to disable - IssueDisableSubnetValidatorTx( + IssueDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, ) (*txs.Tx, error) @@ -437,61 +438,61 @@ func (w *wallet) IssueTransferSubnetOwnershipTx( return w.IssueUnsignedTx(utx, options...) } -func (w *wallet) IssueConvertSubnetTx( +func (w *wallet) IssueConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, ) (*txs.Tx, error) { - utx, err := w.builder.NewConvertSubnetTx(subnetID, chainID, address, validators, options...) + utx, err := w.builder.NewConvertSubnetToL1Tx(subnetID, chainID, address, validators, options...) if err != nil { return nil, err } return w.IssueUnsignedTx(utx, options...) } -func (w *wallet) IssueRegisterSubnetValidatorTx( +func (w *wallet) IssueRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, ) (*txs.Tx, error) { - utx, err := w.builder.NewRegisterSubnetValidatorTx(balance, proofOfPossession, message, options...) + utx, err := w.builder.NewRegisterL1ValidatorTx(balance, proofOfPossession, message, options...) if err != nil { return nil, err } return w.IssueUnsignedTx(utx, options...) } -func (w *wallet) IssueSetSubnetValidatorWeightTx( +func (w *wallet) IssueSetL1ValidatorWeightTx( message []byte, options ...common.Option, ) (*txs.Tx, error) { - utx, err := w.builder.NewSetSubnetValidatorWeightTx(message, options...) + utx, err := w.builder.NewSetL1ValidatorWeightTx(message, options...) if err != nil { return nil, err } return w.IssueUnsignedTx(utx, options...) } -func (w *wallet) IssueIncreaseBalanceTx( +func (w *wallet) IssueIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, ) (*txs.Tx, error) { - utx, err := w.builder.NewIncreaseBalanceTx(validationID, balance, options...) + utx, err := w.builder.NewIncreaseL1ValidatorBalanceTx(validationID, balance, options...) if err != nil { return nil, err } return w.IssueUnsignedTx(utx, options...) } -func (w *wallet) IssueDisableSubnetValidatorTx( +func (w *wallet) IssueDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, ) (*txs.Tx, error) { - utx, err := w.builder.NewDisableSubnetValidatorTx(validationID, options...) + utx, err := w.builder.NewDisableL1ValidatorTx(validationID, options...) if err != nil { return nil, err } diff --git a/wallet/chain/p/wallet/with_options.go b/wallet/chain/p/wallet/with_options.go index d3c704cfbe33..89b3cd660926 100644 --- a/wallet/chain/p/wallet/with_options.go +++ b/wallet/chain/p/wallet/with_options.go @@ -144,14 +144,14 @@ func (w *withOptions) IssueTransferSubnetOwnershipTx( ) } -func (w *withOptions) IssueConvertSubnetTx( +func (w *withOptions) IssueConvertSubnetToL1Tx( subnetID ids.ID, chainID ids.ID, address []byte, - validators []*txs.ConvertSubnetValidator, + validators []*txs.ConvertSubnetToL1Validator, options ...common.Option, ) (*txs.Tx, error) { - return w.wallet.IssueConvertSubnetTx( + return w.wallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, @@ -160,13 +160,13 @@ func (w *withOptions) IssueConvertSubnetTx( ) } -func (w *withOptions) IssueRegisterSubnetValidatorTx( +func (w *withOptions) IssueRegisterL1ValidatorTx( balance uint64, proofOfPossession [bls.SignatureLen]byte, message []byte, options ...common.Option, ) (*txs.Tx, error) { - return w.wallet.IssueRegisterSubnetValidatorTx( + return w.wallet.IssueRegisterL1ValidatorTx( balance, proofOfPossession, message, @@ -174,33 +174,33 @@ func (w *withOptions) IssueRegisterSubnetValidatorTx( ) } -func (w *withOptions) IssueSetSubnetValidatorWeightTx( +func (w *withOptions) IssueSetL1ValidatorWeightTx( message []byte, options ...common.Option, ) (*txs.Tx, error) { - return w.wallet.IssueSetSubnetValidatorWeightTx( + return w.wallet.IssueSetL1ValidatorWeightTx( message, common.UnionOptions(w.options, options)..., ) } -func (w *withOptions) IssueIncreaseBalanceTx( +func (w *withOptions) IssueIncreaseL1ValidatorBalanceTx( validationID ids.ID, balance uint64, options ...common.Option, ) (*txs.Tx, error) { - return w.wallet.IssueIncreaseBalanceTx( + return w.wallet.IssueIncreaseL1ValidatorBalanceTx( validationID, balance, common.UnionOptions(w.options, options)..., ) } -func (w *withOptions) IssueDisableSubnetValidatorTx( +func (w *withOptions) IssueDisableL1ValidatorTx( validationID ids.ID, options ...common.Option, ) (*txs.Tx, error) { - return w.wallet.IssueDisableSubnetValidatorTx( + return w.wallet.IssueDisableL1ValidatorTx( validationID, common.UnionOptions(w.options, options)..., ) diff --git a/wallet/subnet/primary/examples/convert-subnet/main.go b/wallet/subnet/primary/examples/convert-subnet-to-l1/main.go similarity index 88% rename from wallet/subnet/primary/examples/convert-subnet/main.go rename to wallet/subnet/primary/examples/convert-subnet-to-l1/main.go index 8602c26ffb64..62244a61d5b2 100644 --- a/wallet/subnet/primary/examples/convert-subnet/main.go +++ b/wallet/subnet/primary/examples/convert-subnet-to-l1/main.go @@ -44,11 +44,11 @@ func main() { log.Printf("fetched node ID %s in %s\n", nodeID, time.Since(nodeInfoStartTime)) validationID := subnetID.Append(0) - conversionID, err := message.SubnetConversionID(message.SubnetConversionData{ + conversionID, err := message.SubnetToL1ConversionID(message.SubnetToL1ConversionData{ SubnetID: subnetID, ManagerChainID: chainID, ManagerAddress: address, - Validators: []message.SubnetConversionValidatorData{ + Validators: []message.SubnetToL1ConverstionValidatorData{ { NodeID: nodeID.Bytes(), BLSPublicKey: nodePoP.PublicKey, @@ -77,12 +77,12 @@ func main() { // Get the P-chain wallet pWallet := wallet.P() - convertSubnetStartTime := time.Now() - convertSubnetTx, err := pWallet.IssueConvertSubnetTx( + convertSubnetToL1StartTime := time.Now() + convertSubnetToL1Tx, err := pWallet.IssueConvertSubnetToL1Tx( subnetID, chainID, address, - []*txs.ConvertSubnetValidator{ + []*txs.ConvertSubnetToL1Validator{ { NodeID: nodeID.Bytes(), Weight: weight, @@ -98,9 +98,9 @@ func main() { } log.Printf("converted subnet %s with transactionID %s, validationID %s, and conversionID %s in %s\n", subnetID, - convertSubnetTx.ID(), + convertSubnetToL1Tx.ID(), validationID, conversionID, - time.Since(convertSubnetStartTime), + time.Since(convertSubnetToL1StartTime), ) } diff --git a/wallet/subnet/primary/examples/disable-subnet-validator/main.go b/wallet/subnet/primary/examples/disable-l1-validator/main.go similarity index 81% rename from wallet/subnet/primary/examples/disable-subnet-validator/main.go rename to wallet/subnet/primary/examples/disable-l1-validator/main.go index 6fdc1c663824..c396e7b2a3f4 100644 --- a/wallet/subnet/primary/examples/disable-subnet-validator/main.go +++ b/wallet/subnet/primary/examples/disable-l1-validator/main.go @@ -39,16 +39,16 @@ func main() { // Get the P-chain wallet pWallet := wallet.P() - disableSubnetValidatorStartTime := time.Now() - disableSubnetValidatorTx, err := pWallet.IssueDisableSubnetValidatorTx( + disableL1ValidatorStartTime := time.Now() + disableL1ValidatorTx, err := pWallet.IssueDisableL1ValidatorTx( validationID, ) if err != nil { - log.Fatalf("failed to issue disable subnet validator transaction: %s\n", err) + log.Fatalf("failed to issue disable L1 validator transaction: %s\n", err) } log.Printf("disabled %s with %s in %s\n", validationID, - disableSubnetValidatorTx.ID(), - time.Since(disableSubnetValidatorStartTime), + disableL1ValidatorTx.ID(), + time.Since(disableL1ValidatorStartTime), ) } diff --git a/wallet/subnet/primary/examples/increase-balance/main.go b/wallet/subnet/primary/examples/increase-l1-validator-balance/main.go similarity index 85% rename from wallet/subnet/primary/examples/increase-balance/main.go rename to wallet/subnet/primary/examples/increase-l1-validator-balance/main.go index 8374c4888a93..169ba34c000d 100644 --- a/wallet/subnet/primary/examples/increase-balance/main.go +++ b/wallet/subnet/primary/examples/increase-l1-validator-balance/main.go @@ -39,8 +39,8 @@ func main() { // Get the P-chain wallet pWallet := wallet.P() - increaseBalanceStartTime := time.Now() - increaseBalanceTx, err := pWallet.IssueIncreaseBalanceTx( + increaseL1ValidatorBalanceStartTime := time.Now() + increaseL1ValidatorBalanceTx, err := pWallet.IssueIncreaseL1ValidatorBalanceTx( validationID, balance, ) @@ -50,7 +50,7 @@ func main() { log.Printf("increased balance of validationID %s by %d with %s in %s\n", validationID, balance, - increaseBalanceTx.ID(), - time.Since(increaseBalanceStartTime), + increaseL1ValidatorBalanceTx.ID(), + time.Since(increaseL1ValidatorBalanceStartTime), ) } diff --git a/wallet/subnet/primary/examples/register-subnet-validator/main.go b/wallet/subnet/primary/examples/register-l1-validator/main.go similarity index 85% rename from wallet/subnet/primary/examples/register-subnet-validator/main.go rename to wallet/subnet/primary/examples/register-l1-validator/main.go index 68248a7e18eb..2fb6150fd806 100644 --- a/wallet/subnet/primary/examples/register-subnet-validator/main.go +++ b/wallet/subnet/primary/examples/register-l1-validator/main.go @@ -71,7 +71,7 @@ func main() { context := pWallet.Builder().Context() expiry := uint64(time.Now().Add(5 * time.Minute).Unix()) // This message will expire in 5 minutes - addressedCallPayload, err := message.NewRegisterSubnetValidator( + addressedCallPayload, err := message.NewRegisterL1Validator( subnetID, nodeID, nodePoP.PublicKey, @@ -81,11 +81,11 @@ func main() { weight, ) if err != nil { - log.Fatalf("failed to create RegisterSubnetValidator message: %s\n", err) + log.Fatalf("failed to create RegisterL1Validator message: %s\n", err) } addressedCallPayloadJSON, err := json.MarshalIndent(addressedCallPayload, "", "\t") if err != nil { - log.Fatalf("failed to marshal RegisterSubnetValidator message: %s\n", err) + log.Fatalf("failed to marshal RegisterL1Validator message: %s\n", err) } log.Println(string(addressedCallPayloadJSON)) @@ -126,16 +126,16 @@ func main() { log.Fatalf("failed to create Warp message: %s\n", err) } - registerSubnetValidatorStartTime := time.Now() - registerSubnetValidatorTx, err := pWallet.IssueRegisterSubnetValidatorTx( + registerL1ValidatorStartTime := time.Now() + registerL1ValidatorTx, err := pWallet.IssueRegisterL1ValidatorTx( units.Avax, nodePoP.ProofOfPossession, warp.Bytes(), ) if err != nil { - log.Fatalf("failed to issue register subnet validator transaction: %s\n", err) + log.Fatalf("failed to issue register L1 validator transaction: %s\n", err) } validationID := addressedCallPayload.ValidationID() - log.Printf("registered new subnet validator %s to subnet %s with txID %s as validationID %s in %s\n", nodeID, subnetID, registerSubnetValidatorTx.ID(), validationID, time.Since(registerSubnetValidatorStartTime)) + log.Printf("registered new L1 validator %s to subnetID %s with txID %s as validationID %s in %s\n", nodeID, subnetID, registerL1ValidatorTx.ID(), validationID, time.Since(registerL1ValidatorStartTime)) } diff --git a/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go similarity index 89% rename from wallet/subnet/primary/examples/set-subnet-validator-weight/main.go rename to wallet/subnet/primary/examples/set-l1-validator-weight/main.go index a796ae9b51e7..4115bc41a4e2 100644 --- a/wallet/subnet/primary/examples/set-subnet-validator-weight/main.go +++ b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go @@ -60,17 +60,17 @@ func main() { pWallet := wallet.P() context := pWallet.Builder().Context() - addressedCallPayload, err := message.NewSubnetValidatorWeight( + addressedCallPayload, err := message.NewL1ValidatorWeight( validationID, nonce, weight, ) if err != nil { - log.Fatalf("failed to create SubnetValidatorWeight message: %s\n", err) + log.Fatalf("failed to create L1ValidatorWeight message: %s\n", err) } addressedCallPayloadJSON, err := json.MarshalIndent(addressedCallPayload, "", "\t") if err != nil { - log.Fatalf("failed to marshal SubnetValidatorWeight message: %s\n", err) + log.Fatalf("failed to marshal L1ValidatorWeight message: %s\n", err) } log.Println(string(addressedCallPayloadJSON)) @@ -110,11 +110,11 @@ func main() { } setWeightStartTime := time.Now() - setWeightTx, err := pWallet.IssueSetSubnetValidatorWeightTx( + setWeightTx, err := pWallet.IssueSetL1ValidatorWeightTx( warp.Bytes(), ) if err != nil { - log.Fatalf("failed to issue set subnet validator weight transaction: %s\n", err) + log.Fatalf("failed to issue set L1 validator weight transaction: %s\n", err) } log.Printf("issued set weight of validationID %s to %d with nonce %d and txID %s in %s\n", validationID, weight, nonce, setWeightTx.ID(), time.Since(setWeightStartTime)) } diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go b/wallet/subnet/primary/examples/sign-l1-validator-registration/main.go similarity index 93% rename from wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go rename to wallet/subnet/primary/examples/sign-l1-validator-registration/main.go index 71524515ab9e..688bc8c1924c 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-registration/main.go +++ b/wallet/subnet/primary/examples/sign-l1-validator-registration/main.go @@ -38,17 +38,17 @@ func main() { log.Fatalf("failed to fetch network ID: %s\n", err) } - subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration( + l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration( validationID, true, ) if err != nil { - log.Fatalf("failed to create SubnetValidatorRegistration message: %s\n", err) + log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err) } addressedCall, err := payload.NewAddressedCall( nil, - subnetValidatorRegistration.Bytes(), + l1ValidatorRegistration.Bytes(), ) if err != nil { log.Fatalf("failed to create AddressedCall message: %s\n", err) diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go b/wallet/subnet/primary/examples/sign-l1-validator-removal-genesis/main.go similarity index 89% rename from wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go rename to wallet/subnet/primary/examples/sign-l1-validator-removal-genesis/main.go index 7b4eb57e0d69..8dcef4c9c0c9 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-removal-genesis/main.go +++ b/wallet/subnet/primary/examples/sign-l1-validator-removal-genesis/main.go @@ -41,17 +41,17 @@ func main() { } validationID := subnetID.Append(validationIndex) - subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration( + l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration( validationID, false, ) if err != nil { - log.Fatalf("failed to create SubnetValidatorRegistration message: %s\n", err) + log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err) } addressedCall, err := payload.NewAddressedCall( nil, - subnetValidatorRegistration.Bytes(), + l1ValidatorRegistration.Bytes(), ) if err != nil { log.Fatalf("failed to create AddressedCall message: %s\n", err) @@ -66,9 +66,9 @@ func main() { log.Fatalf("failed to create unsigned Warp message: %s\n", err) } - justification := platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_ConvertSubnetTxData{ - ConvertSubnetTxData: &platformvm.SubnetIDIndex{ + justification := platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_ConvertSubnetToL1TxData{ + ConvertSubnetToL1TxData: &platformvm.SubnetIDIndex{ SubnetId: subnetID[:], Index: validationIndex, }, diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go b/wallet/subnet/primary/examples/sign-l1-validator-removal-registration/main.go similarity index 83% rename from wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go rename to wallet/subnet/primary/examples/sign-l1-validator-removal-registration/main.go index aab951eadab6..ef444322e3a2 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-removal-registration/main.go +++ b/wallet/subnet/primary/examples/sign-l1-validator-removal-registration/main.go @@ -30,7 +30,7 @@ import ( warpmessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" ) -var registerSubnetValidatorJSON = []byte(`{ +var registerL1ValidatorJSON = []byte(`{ "subnetID": "2DeHa7Qb6sufPkmQcFWG2uCd4pBPv9WB6dkzroiMQhd1NSRtof", "nodeID": "0x550f3c8f2ebd89e6a69adca196bea38a1b4d65bc", "blsPublicKey": [ @@ -103,28 +103,28 @@ func main() { log.Fatalf("failed to fetch network ID: %s\n", err) } - var registerSubnetValidator warpmessage.RegisterSubnetValidator - err = json.Unmarshal(registerSubnetValidatorJSON, ®isterSubnetValidator) + var registerL1Validator warpmessage.RegisterL1Validator + err = json.Unmarshal(registerL1ValidatorJSON, ®isterL1Validator) if err != nil { - log.Fatalf("failed to unmarshal RegisterSubnetValidator message: %s\n", err) + log.Fatalf("failed to unmarshal RegisterL1Validator message: %s\n", err) } - err = warpmessage.Initialize(®isterSubnetValidator) + err = warpmessage.Initialize(®isterL1Validator) if err != nil { - log.Fatalf("failed to initialize RegisterSubnetValidator message: %s\n", err) + log.Fatalf("failed to initialize RegisterL1Validator message: %s\n", err) } - validationID := registerSubnetValidator.ValidationID() - subnetValidatorRegistration, err := warpmessage.NewSubnetValidatorRegistration( + validationID := registerL1Validator.ValidationID() + l1ValidatorRegistration, err := warpmessage.NewL1ValidatorRegistration( validationID, false, ) if err != nil { - log.Fatalf("failed to create SubnetValidatorRegistration message: %s\n", err) + log.Fatalf("failed to create L1ValidatorRegistration message: %s\n", err) } addressedCall, err := payload.NewAddressedCall( nil, - subnetValidatorRegistration.Bytes(), + l1ValidatorRegistration.Bytes(), ) if err != nil { log.Fatalf("failed to create AddressedCall message: %s\n", err) @@ -139,9 +139,9 @@ func main() { log.Fatalf("failed to create unsigned Warp message: %s\n", err) } - justification := platformvm.SubnetValidatorRegistrationJustification{ - Preimage: &platformvm.SubnetValidatorRegistrationJustification_RegisterSubnetValidatorMessage{ - RegisterSubnetValidatorMessage: registerSubnetValidator.Bytes(), + justification := platformvm.L1ValidatorRegistrationJustification{ + Preimage: &platformvm.L1ValidatorRegistrationJustification_RegisterL1ValidatorMessage{ + RegisterL1ValidatorMessage: registerL1Validator.Bytes(), }, } justificationBytes, err := proto.Marshal(&justification) diff --git a/wallet/subnet/primary/examples/sign-subnet-validator-weight/main.go b/wallet/subnet/primary/examples/sign-l1-validator-weight/main.go similarity index 87% rename from wallet/subnet/primary/examples/sign-subnet-validator-weight/main.go rename to wallet/subnet/primary/examples/sign-l1-validator-weight/main.go index 26a8dd1cfcb3..29ff26455424 100644 --- a/wallet/subnet/primary/examples/sign-subnet-validator-weight/main.go +++ b/wallet/subnet/primary/examples/sign-l1-validator-weight/main.go @@ -29,7 +29,7 @@ import ( warpmessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" ) -var subnetValidatorWeightJSON = []byte(`{ +var l1ValidatorWeightJSON = []byte(`{ "validationID": "2Y3ZZZXxpzm46geqVuqFXeSFVbeKihgrfeXRDaiF4ds6R2N8M5", "nonce": 1, "weight": 2 @@ -43,19 +43,19 @@ func main() { log.Fatalf("failed to fetch network ID: %s\n", err) } - var subnetValidatorWeight warpmessage.SubnetValidatorWeight - err = json.Unmarshal(subnetValidatorWeightJSON, &subnetValidatorWeight) + var l1ValidatorWeight warpmessage.L1ValidatorWeight + err = json.Unmarshal(l1ValidatorWeightJSON, &l1ValidatorWeight) if err != nil { - log.Fatalf("failed to unmarshal SubnetValidatorWeight message: %s\n", err) + log.Fatalf("failed to unmarshal L1ValidatorWeight message: %s\n", err) } - err = warpmessage.Initialize(&subnetValidatorWeight) + err = warpmessage.Initialize(&l1ValidatorWeight) if err != nil { - log.Fatalf("failed to initialize SubnetValidatorWeight message: %s\n", err) + log.Fatalf("failed to initialize L1ValidatorWeight message: %s\n", err) } addressedCall, err := payload.NewAddressedCall( nil, - subnetValidatorWeight.Bytes(), + l1ValidatorWeight.Bytes(), ) if err != nil { log.Fatalf("failed to create AddressedCall message: %s\n", err) diff --git a/wallet/subnet/primary/examples/sign-subnet-conversion/main.go b/wallet/subnet/primary/examples/sign-subnet-to-l1-conversion/main.go similarity index 94% rename from wallet/subnet/primary/examples/sign-subnet-conversion/main.go rename to wallet/subnet/primary/examples/sign-subnet-to-l1-conversion/main.go index 1d3fdd7a47de..b4ba05a7948e 100644 --- a/wallet/subnet/primary/examples/sign-subnet-conversion/main.go +++ b/wallet/subnet/primary/examples/sign-subnet-to-l1-conversion/main.go @@ -39,14 +39,14 @@ func main() { log.Fatalf("failed to fetch network ID: %s\n", err) } - subnetConversion, err := warpmessage.NewSubnetConversion(conversionID) + subnetToL1Conversion, err := warpmessage.NewSubnetToL1Conversion(conversionID) if err != nil { - log.Fatalf("failed to create SubnetConversion message: %s\n", err) + log.Fatalf("failed to create SubnetToL1Conversion message: %s\n", err) } addressedCall, err := payload.NewAddressedCall( nil, - subnetConversion.Bytes(), + subnetToL1Conversion.Bytes(), ) if err != nil { log.Fatalf("failed to create AddressedCall message: %s\n", err)