Merge pull request #1 from StephenButtolph/custom-genesis

Custom genesis
This commit is contained in:
danlaine 2020-03-17 13:08:53 -04:00 committed by GitHub
commit bace8991c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 101 additions and 106 deletions

View File

@ -162,7 +162,7 @@ func (tx *addNonDefaultSubnetValidatorTx) SemanticVerify(db database.Database) (
} }
var subnet *CreateSubnetTx var subnet *CreateSubnetTx
for _, sn := range subnets { for _, sn := range subnets {
if sn.ID.Equals(tx.SubnetID()) { if sn.id.Equals(tx.SubnetID()) {
subnet = sn subnet = sn
break break
} }

View File

@ -28,7 +28,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -48,7 +48,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID+1, testNetworkID+1,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -67,7 +67,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -87,7 +87,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -107,7 +107,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -126,7 +126,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix())-1, uint64(defaultValidateEndTime.Unix())-1,
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -147,7 +147,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateStartTime.Add(MinimumStakingDuration).Unix())-1, uint64(defaultValidateStartTime.Add(MinimumStakingDuration).Unix())-1,
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -167,7 +167,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateStartTime.Add(MaximumStakingDuration).Unix())+1, uint64(defaultValidateStartTime.Add(MaximumStakingDuration).Unix())+1,
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -187,7 +187,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -212,7 +212,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix())+1, uint64(defaultValidateEndTime.Unix())+1,
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -235,7 +235,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -245,7 +245,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
} }
_, _, _, _, err = tx.SemanticVerify(vm.DB) _, _, _, _, err = tx.SemanticVerify(vm.DB)
if err != nil { if err != nil {
t.Log(testSubnet1.ID) t.Log(testSubnet1.id)
subnets, err := vm.getSubnets(vm.DB) subnets, err := vm.getSubnets(vm.DB)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -253,7 +253,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
if len(subnets) == 0 { if len(subnets) == 0 {
t.Fatal("no subnets found") t.Fatal("no subnets found")
} }
t.Logf("subnets[0].ID: %v", subnets[0].ID) t.Logf("subnets[0].ID: %v", subnets[0].id)
t.Fatal(err) t.Fatal(err)
} }
@ -290,7 +290,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(DSStartTime.Unix()), // start validating non-default subnet before default subnet uint64(DSStartTime.Unix()), // start validating non-default subnet before default subnet
uint64(DSEndTime.Unix()), uint64(DSEndTime.Unix()),
pendingDSValidatorID, pendingDSValidatorID,
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -324,7 +324,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(DSStartTime.Unix())-1, // start validating non-default subnet before default subnet uint64(DSStartTime.Unix())-1, // start validating non-default subnet before default subnet
uint64(DSEndTime.Unix()), uint64(DSEndTime.Unix()),
pendingDSValidatorID, pendingDSValidatorID,
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -346,7 +346,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(DSStartTime.Unix()), uint64(DSStartTime.Unix()),
uint64(DSEndTime.Unix())+1, // stop validating non-default subnet after stopping validating default subnet uint64(DSEndTime.Unix())+1, // stop validating non-default subnet after stopping validating default subnet
pendingDSValidatorID, pendingDSValidatorID,
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -368,7 +368,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(DSStartTime.Unix()), // same start time as for default subnet uint64(DSStartTime.Unix()), // same start time as for default subnet
uint64(DSEndTime.Unix()), // same end time as for default subnet uint64(DSEndTime.Unix()), // same end time as for default subnet
pendingDSValidatorID, pendingDSValidatorID,
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,
@ -389,12 +389,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
} }
tx, err = vm.newAddNonDefaultSubnetValidatorTx( tx, err = vm.newAddNonDefaultSubnetValidatorTx(
defaultNonce+1, // nonce defaultNonce+1, // nonce
defaultWeight, // weight defaultWeight, // weight
uint64(newTimestamp.Unix()), // start time uint64(newTimestamp.Unix()), // start time
uint64(newTimestamp.Add(MinimumStakingDuration).Unix()), // end time uint64(newTimestamp.Add(MinimumStakingDuration).Unix()), // end time
defaultKey.PublicKey().Address(), // node ID defaultKey.PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -429,7 +429,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), // start time uint64(defaultValidateStartTime.Unix()), // start time
uint64(defaultValidateEndTime.Unix()), // end time uint64(defaultValidateEndTime.Unix()), // end time
defaultKey.PublicKey().Address(), // node ID defaultKey.PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
newAcctKey.(*crypto.PrivateKeySECP256K1R), // tx fee payer newAcctKey.(*crypto.PrivateKeySECP256K1R), // tx fee payer
@ -451,7 +451,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), // start time uint64(defaultValidateStartTime.Unix()), // start time
uint64(defaultValidateEndTime.Unix()), // end time uint64(defaultValidateEndTime.Unix()), // end time
defaultKey.PublicKey().Address(), // node ID defaultKey.PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -465,7 +465,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
SortByStartTime: false, SortByStartTime: false,
Txs: []TimedTx{tx}, Txs: []TimedTx{tx},
}, },
testSubnet1.ID, testSubnet1.id,
) )
// Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID // Node with ID nodeIDKey.PublicKey().Address() now validating subnet with ID testSubnet1.ID
@ -475,7 +475,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), // start time uint64(defaultValidateStartTime.Unix()), // start time
uint64(defaultValidateEndTime.Unix()), // end time uint64(defaultValidateEndTime.Unix()), // end time
defaultKey.PublicKey().Address(), // node ID defaultKey.PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -494,17 +494,17 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
&EventHeap{ &EventHeap{
SortByStartTime: false, SortByStartTime: false,
}, },
testSubnet1.ID, testSubnet1.id,
) )
// Case 9: Too many signatures // Case 9: Too many signatures
tx, err = vm.newAddNonDefaultSubnetValidatorTx( tx, err = vm.newAddNonDefaultSubnetValidatorTx(
defaultNonce+1, // nonce defaultNonce+1, // nonce
defaultWeight, // weight defaultWeight, // weight
uint64(defaultGenesisTime.Unix()), // start time uint64(defaultGenesisTime.Unix()), // start time
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time
keys[0].PublicKey().Address(), // node ID keys[0].PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -520,12 +520,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
// Case 10: Too few signatures // Case 10: Too few signatures
tx, err = vm.newAddNonDefaultSubnetValidatorTx( tx, err = vm.newAddNonDefaultSubnetValidatorTx(
defaultNonce+1, // nonce defaultNonce+1, // nonce
defaultWeight, // weight defaultWeight, // weight
uint64(defaultGenesisTime.Unix()), // start time uint64(defaultGenesisTime.Unix()), // start time
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time
keys[0].PublicKey().Address(), // node ID keys[0].PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[2]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[2]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -541,12 +541,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
// Case 10: Control Signature from invalid key // Case 10: Control Signature from invalid key
tx, err = vm.newAddNonDefaultSubnetValidatorTx( tx, err = vm.newAddNonDefaultSubnetValidatorTx(
defaultNonce+1, // nonce defaultNonce+1, // nonce
defaultWeight, // weight defaultWeight, // weight
uint64(defaultGenesisTime.Unix()), // start time uint64(defaultGenesisTime.Unix()), // start time
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time
keys[0].PublicKey().Address(), // node ID keys[0].PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], keys[3]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], keys[3]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -563,12 +563,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
// Case 11: Proposed validator in pending validator set for subnet // Case 11: Proposed validator in pending validator set for subnet
// First, add validator to pending validator set of subnet // First, add validator to pending validator set of subnet
tx, err = vm.newAddNonDefaultSubnetValidatorTx( tx, err = vm.newAddNonDefaultSubnetValidatorTx(
defaultNonce+1, // nonce defaultNonce+1, // nonce
defaultWeight, // weight defaultWeight, // weight
uint64(defaultGenesisTime.Unix())+1, // start time uint64(defaultGenesisTime.Unix())+1, // start time
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time
defaultKey.PublicKey().Address(), // node ID defaultKey.PublicKey().Address(), // node ID
testSubnet1.ID, // subnet ID testSubnet1.id, // subnet ID
testNetworkID, // network ID testNetworkID, // network ID
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, // tx fee payer defaultKey, // tx fee payer
@ -582,7 +582,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
SortByStartTime: true, SortByStartTime: true,
Txs: []TimedTx{tx}, Txs: []TimedTx{tx},
}, },
testSubnet1.ID, testSubnet1.id,
) )
// Node with ID nodeIDKey.PublicKey().Address() now pending validator for subnet with ID testSubnet1.ID // Node with ID nodeIDKey.PublicKey().Address() now pending validator for subnet with ID testSubnet1.ID
@ -604,7 +604,7 @@ func TestAddNonDefaultSubnetValidatorMarshal(t *testing.T) {
uint64(defaultValidateStartTime.Unix()), uint64(defaultValidateStartTime.Unix()),
uint64(defaultValidateEndTime.Unix()), uint64(defaultValidateEndTime.Unix()),
defaultKey.PublicKey().Address(), defaultKey.PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
defaultKey, defaultKey,

View File

@ -105,15 +105,15 @@ func (tx *advanceTimeTx) SemanticVerify(db database.Database) (*versiondb.Databa
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
for _, subnet := range subnets { for _, subnet := range subnets {
current, pending, err := tx.vm.calculateValidators(db, tx.Timestamp(), subnet.ID) current, pending, err := tx.vm.calculateValidators(db, tx.Timestamp(), subnet.id)
if err != nil { if err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
if err := tx.vm.putCurrentValidators(onCommitDB, current, subnet.ID); err != nil { if err := tx.vm.putCurrentValidators(onCommitDB, current, subnet.id); err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
if err := tx.vm.putPendingValidators(onCommitDB, pending, subnet.ID); err != nil { if err := tx.vm.putPendingValidators(onCommitDB, pending, subnet.id); err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
} }
@ -127,7 +127,7 @@ func (tx *advanceTimeTx) SemanticVerify(db database.Database) (*versiondb.Databa
return return
} }
for _, subnet := range subnets { for _, subnet := range subnets {
if err := tx.vm.updateValidators(subnet.ID); err != nil { if err := tx.vm.updateValidators(subnet.id); err != nil {
tx.vm.Ctx.Log.Debug("failed to update validators on the default subnet: %s", err) tx.vm.Ctx.Log.Debug("failed to update validators on the default subnet: %s", err)
} }
} }

View File

@ -156,7 +156,7 @@ func (tx *CreateChainTx) SemanticVerify(db database.Database) (func(), error) {
} }
var subnet *CreateSubnetTx // the subnet that will validate the new chain var subnet *CreateSubnetTx // the subnet that will validate the new chain
for _, sn := range subnets { for _, sn := range subnets {
if sn.ID.Equals(tx.SubnetID) { if sn.id.Equals(tx.SubnetID) {
subnet = sn subnet = sn
break break
} }

View File

@ -24,7 +24,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 2: network ID is wrong // Case 2: network ID is wrong
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -44,7 +44,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// case 3: tx ID is empty // case 3: tx ID is empty
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -64,7 +64,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 4: vm ID is empty // Case 4: vm ID is empty
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -84,7 +84,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 5: Control sigs not sorted // Case 5: Control sigs not sorted
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -105,7 +105,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 6: Control sigs not unique // Case 6: Control sigs not unique
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -125,7 +125,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 7: Control sigs are nil // Case 7: Control sigs are nil
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -145,7 +145,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
// Case 8: Valid tx passes syntactic verification // Case 8: Valid tx passes syntactic verification
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -166,7 +166,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
// Case 1: No control sigs (2 are needed) // Case 1: No control sigs (2 are needed)
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -187,7 +187,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
// Case 2: 1 control sig (2 are needed) // Case 2: 1 control sig (2 are needed)
tx, err = vm.newCreateChainTx( tx, err = vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -219,7 +219,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) {
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -269,7 +269,7 @@ func TestCreateChainTxAlreadyExists(t *testing.T) {
// create a tx // create a tx
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,
@ -300,7 +300,7 @@ func TestCreateChainTxValid(t *testing.T) {
// create a valid tx // create a valid tx
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
avm.ID, avm.ID,
nil, nil,

View File

@ -7,11 +7,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/ava-labs/gecko/snow/validators"
"github.com/ava-labs/gecko/database" "github.com/ava-labs/gecko/database"
"github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow/validators"
"github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/hashing" "github.com/ava-labs/gecko/utils/hashing"
) )
@ -28,9 +26,6 @@ type UnsignedCreateSubnetTx struct {
// The VM this tx exists within // The VM this tx exists within
vm *VM vm *VM
// ID is this transaction's ID
ID ids.ID
// NetworkID is the ID of the network this tx was issued on // NetworkID is the ID of the network this tx was issued on
NetworkID uint32 `serialize:"true"` NetworkID uint32 `serialize:"true"`
@ -49,19 +44,25 @@ type UnsignedCreateSubnetTx struct {
type CreateSubnetTx struct { type CreateSubnetTx struct {
UnsignedCreateSubnetTx `serialize:"true"` UnsignedCreateSubnetTx `serialize:"true"`
// Signature on the UnsignedCreateSubnetTx's byte repr
Sig [crypto.SECP256K1RSigLen]byte `serialize:"true"`
// The public key that signed this transaction // The public key that signed this transaction
// The transaction fee will be paid from the corresponding account // The transaction fee will be paid from the corresponding account
// (ie the account whose ID is [key].Address()) // (ie the account whose ID is [key].Address())
// [key] is non-nil iff this tx is valid // [key] is non-nil iff this tx is valid
key crypto.PublicKey key crypto.PublicKey
// Signature on the UnsignedCreateSubnetTx's byte repr // ID is this transaction's ID
Sig [crypto.SECP256K1RSigLen]byte `serialize:"true"` id ids.ID
// Byte representation of this transaction (including signature) // Byte representation of this transaction (including signature)
bytes []byte bytes []byte
} }
// ID returns the ID of this transaction
func (tx *CreateSubnetTx) ID() ids.ID { return tx.id }
// SyntacticVerify nil iff [tx] is syntactically valid. // SyntacticVerify nil iff [tx] is syntactically valid.
// If [tx] is valid, this method sets [tx.key] // If [tx] is valid, this method sets [tx.key]
func (tx *CreateSubnetTx) SyntacticVerify() error { func (tx *CreateSubnetTx) SyntacticVerify() error {
@ -70,7 +71,7 @@ func (tx *CreateSubnetTx) SyntacticVerify() error {
return errNilTx return errNilTx
case tx.key != nil: case tx.key != nil:
return nil // Only verify the transaction once return nil // Only verify the transaction once
case tx.ID.IsZero(): case tx.id.IsZero():
return errInvalidID return errInvalidID
case tx.NetworkID != tx.vm.Ctx.NetworkID: case tx.NetworkID != tx.vm.Ctx.NetworkID:
return errWrongNetworkID return errWrongNetworkID
@ -108,8 +109,8 @@ func (tx *CreateSubnetTx) SemanticVerify(db database.Database) (func(), error) {
} }
for _, subnet := range subnets { for _, subnet := range subnets {
if subnet.ID.Equals(tx.ID) { if subnet.id.Equals(tx.id) {
return nil, fmt.Errorf("there is already a subnet with ID %s", tx.ID) return nil, fmt.Errorf("there is already a subnet with ID %s", tx.id)
} }
} }
subnets = append(subnets, tx) // add new subnet subnets = append(subnets, tx) // add new subnet
@ -132,7 +133,7 @@ func (tx *CreateSubnetTx) SemanticVerify(db database.Database) (func(), error) {
// Register new subnet in validator manager // Register new subnet in validator manager
onAccept := func() { onAccept := func() {
tx.vm.Validators.PutValidatorSet(tx.ID, validators.NewSet()) tx.vm.Validators.PutValidatorSet(tx.id, validators.NewSet())
} }
return onAccept, nil return onAccept, nil
@ -159,7 +160,7 @@ func (tx *CreateSubnetTx) initialize(vm *VM) error {
return err return err
} }
tx.bytes = txBytes tx.bytes = txBytes
tx.ID = ids.NewID(hashing.ComputeHash256Array(txBytes)) tx.id = ids.NewID(hashing.ComputeHash256Array(txBytes))
return nil return nil
} }

View File

@ -78,7 +78,7 @@ func (service *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, respon
response.Subnets = make([]APISubnet, len(subnets)) response.Subnets = make([]APISubnet, len(subnets))
for i, subnet := range subnets { for i, subnet := range subnets {
response.Subnets[i] = APISubnet{ response.Subnets[i] = APISubnet{
ID: subnet.ID, ID: subnet.id,
ControlKeys: subnet.ControlKeys, ControlKeys: subnet.ControlKeys,
Threshold: json.Uint16(subnet.Threshold), Threshold: json.Uint16(subnet.Threshold),
} }
@ -89,10 +89,10 @@ func (service *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, respon
idsSet := ids.Set{} idsSet := ids.Set{}
idsSet.Add(args.IDs...) idsSet.Add(args.IDs...)
for _, subnet := range subnets { for _, subnet := range subnets {
if idsSet.Contains(subnet.ID) { if idsSet.Contains(subnet.id) {
response.Subnets = append(response.Subnets, response.Subnets = append(response.Subnets,
APISubnet{ APISubnet{
ID: subnet.ID, ID: subnet.id,
ControlKeys: subnet.ControlKeys, ControlKeys: subnet.ControlKeys,
Threshold: json.Uint16(subnet.Threshold), Threshold: json.Uint16(subnet.Threshold),
}, },
@ -837,15 +837,7 @@ func (service *Service) IssueTx(_ *http.Request, args *IssueTxArgs, response *Is
defer service.vm.resetTimer() defer service.vm.resetTimer()
response.TxID = tx.ID() response.TxID = tx.ID()
return nil return nil
case *CreateSubnetTx: case DecisionTx:
if err := tx.initialize(service.vm); err != nil {
return fmt.Errorf("error initializing tx: %s", err)
}
service.vm.unissuedDecisionTxs = append(service.vm.unissuedDecisionTxs, tx)
defer service.vm.resetTimer()
response.TxID = tx.ID
return nil
case *CreateChainTx:
if err := tx.initialize(service.vm); err != nil { if err := tx.initialize(service.vm); err != nil {
return fmt.Errorf("error initializing tx: %s", err) return fmt.Errorf("error initializing tx: %s", err)
} }
@ -854,7 +846,7 @@ func (service *Service) IssueTx(_ *http.Request, args *IssueTxArgs, response *Is
response.TxID = tx.ID() response.TxID = tx.ID()
return nil return nil
default: default:
return errors.New("Could not parse given tx. Must be one of: addDefaultSubnetValidatorTx, addDefaultSubnetDelegatorTx, addNonDefaultSubnetValidatorTx, createSubnetTx") return errors.New("Could not parse given tx. Must be either a TimedTx or a DecisionTx")
} }
} }

View File

@ -12,6 +12,8 @@ import (
// DecisionTx is an operation that can be decided without being proposed // DecisionTx is an operation that can be decided without being proposed
type DecisionTx interface { type DecisionTx interface {
ID() ids.ID
initialize(vm *VM) error initialize(vm *VM) error
// Attempt to verify this transaction with the provided state. The provided // Attempt to verify this transaction with the provided state. The provided

View File

@ -211,18 +211,18 @@ func (vm *VM) getSubnets(db database.Database) ([]*CreateSubnetTx, error) {
} }
// get the subnet with the specified ID // get the subnet with the specified ID
func (vm *VM) getSubnet(db database.Database, ID ids.ID) (*CreateSubnetTx, error) { func (vm *VM) getSubnet(db database.Database, id ids.ID) (*CreateSubnetTx, error) {
subnets, err := vm.getSubnets(db) subnets, err := vm.getSubnets(db)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, subnet := range subnets { for _, subnet := range subnets {
if subnet.ID.Equals(ID) { if subnet.id.Equals(id) {
return subnet, nil return subnet, nil
} }
} }
return nil, fmt.Errorf("couldn't find subnet with ID %s", ID) return nil, fmt.Errorf("couldn't find subnet with ID %s", id)
} }
// register each type that we'll be storing in the database // register each type that we'll be storing in the database

View File

@ -318,7 +318,7 @@ func (vm *VM) initSubnets() error {
} }
for _, subnet := range subnets { for _, subnet := range subnets {
if err := vm.updateValidators(subnet.ID); err != nil { if err := vm.updateValidators(subnet.id); err != nil {
return err return err
} }
} }
@ -621,7 +621,7 @@ func (vm *VM) nextValidatorChangeTime(db database.Database, start bool) time.Tim
return earliest return earliest
} }
for _, subnet := range subnets { for _, subnet := range subnets {
t := vm.nextSubnetValidatorChangeTime(db, subnet.ID, start) t := vm.nextSubnetValidatorChangeTime(db, subnet.id, start)
if t.Before(earliest) { if t.Before(earliest) {
earliest = t earliest = t
} }

View File

@ -153,7 +153,7 @@ func defaultVM() *VM {
&EventHeap{ &EventHeap{
SortByStartTime: false, SortByStartTime: false,
}, },
tx.ID, tx.id,
) )
if err != nil { if err != nil {
panic(err) panic(err)
@ -163,7 +163,7 @@ func defaultVM() *VM {
&EventHeap{ &EventHeap{
SortByStartTime: true, SortByStartTime: true,
}, },
tx.ID, tx.id,
) )
if err != nil { if err != nil {
panic(err) panic(err)
@ -437,7 +437,7 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
uint64(startTime.Unix()), uint64(startTime.Unix()),
uint64(endTime.Unix()), uint64(endTime.Unix()),
keys[0].PublicKey().Address(), keys[0].PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
keys[0], keys[0],
@ -482,7 +482,7 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
commit.Accept() // accept the proposal commit.Accept() // accept the proposal
// Verify that new validator is in pending validator set // Verify that new validator is in pending validator set
pendingValidators, err := vm.getPendingValidators(vm.DB, testSubnet1.ID) pendingValidators, err := vm.getPendingValidators(vm.DB, testSubnet1.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -510,7 +510,7 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
uint64(startTime.Unix()), uint64(startTime.Unix()),
uint64(endTime.Unix()), uint64(endTime.Unix()),
keys[0].PublicKey().Address(), keys[0].PublicKey().Address(),
testSubnet1.ID, testSubnet1.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]}, []*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]},
keys[0], keys[0],
@ -555,7 +555,7 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
abort.Accept() // reject the proposal abort.Accept() // reject the proposal
// Verify that new validator NOT in pending validator set // Verify that new validator NOT in pending validator set
pendingValidators, err := vm.getPendingValidators(vm.DB, testSubnet1.ID) pendingValidators, err := vm.getPendingValidators(vm.DB, testSubnet1.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -765,7 +765,7 @@ func TestCreateChain(t *testing.T) {
tx, err := vm.newCreateChainTx( tx, err := vm.newCreateChainTx(
defaultNonce+1, defaultNonce+1,
testSubnet1.ID, testSubnet1.id,
nil, nil,
timestampvm.ID, timestampvm.ID,
nil, nil,
@ -887,7 +887,7 @@ func TestCreateSubnet(t *testing.T) {
uint64(startTime.Unix()), uint64(startTime.Unix()),
uint64(endTime.Unix()), uint64(endTime.Unix()),
keys[0].PublicKey().Address(), keys[0].PublicKey().Address(),
createSubnetTx.ID, createSubnetTx.id,
testNetworkID, testNetworkID,
[]*crypto.PrivateKeySECP256K1R{keys[0]}, []*crypto.PrivateKeySECP256K1R{keys[0]},
keys[0], keys[0],
@ -937,7 +937,7 @@ func TestCreateSubnet(t *testing.T) {
commit.Accept() // add the validator to pending validator set commit.Accept() // add the validator to pending validator set
// Verify validator is in pending validator set // Verify validator is in pending validator set
pendingValidators, err := vm.getPendingValidators(vm.DB, createSubnetTx.ID) pendingValidators, err := vm.getPendingValidators(vm.DB, createSubnetTx.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -991,7 +991,7 @@ func TestCreateSubnet(t *testing.T) {
// Verify validator no longer in pending validator set // Verify validator no longer in pending validator set
// Verify validator is in pending validator set // Verify validator is in pending validator set
pendingValidators, err = vm.getPendingValidators(vm.DB, createSubnetTx.ID) pendingValidators, err = vm.getPendingValidators(vm.DB, createSubnetTx.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1000,7 +1000,7 @@ func TestCreateSubnet(t *testing.T) {
} }
// Verify validator is in current validator set // Verify validator is in current validator set
currentValidators, err := vm.getCurrentValidators(vm.DB, createSubnetTx.ID) currentValidators, err := vm.getCurrentValidators(vm.DB, createSubnetTx.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1050,14 +1050,14 @@ func TestCreateSubnet(t *testing.T) {
commit.Accept() // remove validator from current validator set commit.Accept() // remove validator from current validator set
// pending validators and current validator should be empty // pending validators and current validator should be empty
pendingValidators, err = vm.getPendingValidators(vm.DB, createSubnetTx.ID) pendingValidators, err = vm.getPendingValidators(vm.DB, createSubnetTx.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if pendingValidators.Len() != 0 { if pendingValidators.Len() != 0 {
t.Fatal("pending validator set should be empty") t.Fatal("pending validator set should be empty")
} }
currentValidators, err = vm.getCurrentValidators(vm.DB, createSubnetTx.ID) currentValidators, err = vm.getCurrentValidators(vm.DB, createSubnetTx.id)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }