mirror of https://github.com/poanetwork/gecko.git
Merge pull request #1 from StephenButtolph/custom-genesis
Custom genesis
This commit is contained in:
commit
bace8991c0
|
@ -162,7 +162,7 @@ func (tx *addNonDefaultSubnetValidatorTx) SemanticVerify(db database.Database) (
|
|||
}
|
||||
var subnet *CreateSubnetTx
|
||||
for _, sn := range subnets {
|
||||
if sn.ID.Equals(tx.SubnetID()) {
|
||||
if sn.id.Equals(tx.SubnetID()) {
|
||||
subnet = sn
|
||||
break
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -48,7 +48,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID+1,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -67,7 +67,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -87,7 +87,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -107,7 +107,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -126,7 +126,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix())-1,
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -147,7 +147,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateStartTime.Add(MinimumStakingDuration).Unix())-1,
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -167,7 +167,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateStartTime.Add(MaximumStakingDuration).Unix())+1,
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -187,7 +187,7 @@ func TestAddNonDefaultSubnetValidatorTxSyntacticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -212,7 +212,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix())+1,
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -235,7 +235,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()),
|
||||
uint64(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -245,7 +245,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
}
|
||||
_, _, _, _, err = tx.SemanticVerify(vm.DB)
|
||||
if err != nil {
|
||||
t.Log(testSubnet1.ID)
|
||||
t.Log(testSubnet1.id)
|
||||
subnets, err := vm.getSubnets(vm.DB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -253,7 +253,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
if len(subnets) == 0 {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(DSStartTime.Unix()), // start validating non-default subnet before default subnet
|
||||
uint64(DSEndTime.Unix()),
|
||||
pendingDSValidatorID,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -324,7 +324,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(DSStartTime.Unix())-1, // start validating non-default subnet before default subnet
|
||||
uint64(DSEndTime.Unix()),
|
||||
pendingDSValidatorID,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -346,7 +346,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(DSStartTime.Unix()),
|
||||
uint64(DSEndTime.Unix())+1, // stop validating non-default subnet after stopping validating default subnet
|
||||
pendingDSValidatorID,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -368,7 +368,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(DSStartTime.Unix()), // same start time as for default subnet
|
||||
uint64(DSEndTime.Unix()), // same end time as for default subnet
|
||||
pendingDSValidatorID,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
@ -389,12 +389,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
}
|
||||
|
||||
tx, err = vm.newAddNonDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(newTimestamp.Unix()), // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(newTimestamp.Unix()), // start time
|
||||
uint64(newTimestamp.Add(MinimumStakingDuration).Unix()), // end time
|
||||
defaultKey.PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -429,7 +429,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()), // start time
|
||||
uint64(defaultValidateEndTime.Unix()), // end time
|
||||
defaultKey.PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
newAcctKey.(*crypto.PrivateKeySECP256K1R), // tx fee payer
|
||||
|
@ -451,7 +451,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
uint64(defaultValidateStartTime.Unix()), // start time
|
||||
uint64(defaultValidateEndTime.Unix()), // end time
|
||||
defaultKey.PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -465,7 +465,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
SortByStartTime: false,
|
||||
Txs: []TimedTx{tx},
|
||||
},
|
||||
testSubnet1.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(defaultValidateEndTime.Unix()), // end time
|
||||
defaultKey.PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -494,17 +494,17 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
&EventHeap{
|
||||
SortByStartTime: false,
|
||||
},
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
)
|
||||
|
||||
// Case 9: Too many signatures
|
||||
tx, err = vm.newAddNonDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time
|
||||
keys[0].PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -520,12 +520,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
|
||||
// Case 10: Too few signatures
|
||||
tx, err = vm.newAddNonDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time
|
||||
keys[0].PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[2]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -541,12 +541,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
|
||||
// Case 10: Control Signature from invalid key
|
||||
tx, err = vm.newAddNonDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix()), // start time
|
||||
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix()), // end time
|
||||
keys[0].PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], keys[3]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -563,12 +563,12 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
// Case 11: Proposed validator in pending validator set for subnet
|
||||
// First, add validator to pending validator set of subnet
|
||||
tx, err = vm.newAddNonDefaultSubnetValidatorTx(
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix())+1, // start time
|
||||
defaultNonce+1, // nonce
|
||||
defaultWeight, // weight
|
||||
uint64(defaultGenesisTime.Unix())+1, // start time
|
||||
uint64(defaultGenesisTime.Add(MinimumStakingDuration).Unix())+1, // end time
|
||||
defaultKey.PublicKey().Address(), // node ID
|
||||
testSubnet1.ID, // subnet ID
|
||||
testSubnet1.id, // subnet ID
|
||||
testNetworkID, // network ID
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey, // tx fee payer
|
||||
|
@ -582,7 +582,7 @@ func TestAddNonDefaultSubnetValidatorTxSemanticVerify(t *testing.T) {
|
|||
SortByStartTime: true,
|
||||
Txs: []TimedTx{tx},
|
||||
},
|
||||
testSubnet1.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(defaultValidateEndTime.Unix()),
|
||||
defaultKey.PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
defaultKey,
|
||||
|
|
|
@ -105,15 +105,15 @@ func (tx *advanceTimeTx) SemanticVerify(db database.Database) (*versiondb.Databa
|
|||
return nil, nil, nil, nil, err
|
||||
}
|
||||
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 {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func (tx *advanceTimeTx) SemanticVerify(db database.Database) (*versiondb.Databa
|
|||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ func (tx *CreateChainTx) SemanticVerify(db database.Database) (func(), error) {
|
|||
}
|
||||
var subnet *CreateSubnetTx // the subnet that will validate the new chain
|
||||
for _, sn := range subnets {
|
||||
if sn.ID.Equals(tx.SubnetID) {
|
||||
if sn.id.Equals(tx.SubnetID) {
|
||||
subnet = sn
|
||||
break
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 2: network ID is wrong
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -44,7 +44,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// case 3: tx ID is empty
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -64,7 +64,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 4: vm ID is empty
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -84,7 +84,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 5: Control sigs not sorted
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -105,7 +105,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 6: Control sigs not unique
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -125,7 +125,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 7: Control sigs are nil
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -145,7 +145,7 @@ func TestCreateChainTxSyntacticVerify(t *testing.T) {
|
|||
// Case 8: Valid tx passes syntactic verification
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -166,7 +166,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
|
|||
// Case 1: No control sigs (2 are needed)
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -187,7 +187,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) {
|
|||
// Case 2: 1 control sig (2 are needed)
|
||||
tx, err = vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -219,7 +219,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) {
|
|||
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -269,7 +269,7 @@ func TestCreateChainTxAlreadyExists(t *testing.T) {
|
|||
// create a tx
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
@ -300,7 +300,7 @@ func TestCreateChainTxValid(t *testing.T) {
|
|||
// create a valid tx
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
avm.ID,
|
||||
nil,
|
||||
|
|
|
@ -7,11 +7,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ava-labs/gecko/snow/validators"
|
||||
|
||||
"github.com/ava-labs/gecko/database"
|
||||
|
||||
"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/hashing"
|
||||
)
|
||||
|
@ -28,9 +26,6 @@ type UnsignedCreateSubnetTx struct {
|
|||
// The VM this tx exists within
|
||||
vm *VM
|
||||
|
||||
// ID is this transaction's ID
|
||||
ID ids.ID
|
||||
|
||||
// NetworkID is the ID of the network this tx was issued on
|
||||
NetworkID uint32 `serialize:"true"`
|
||||
|
||||
|
@ -49,19 +44,25 @@ type UnsignedCreateSubnetTx struct {
|
|||
type CreateSubnetTx struct {
|
||||
UnsignedCreateSubnetTx `serialize:"true"`
|
||||
|
||||
// Signature on the UnsignedCreateSubnetTx's byte repr
|
||||
Sig [crypto.SECP256K1RSigLen]byte `serialize:"true"`
|
||||
|
||||
// The public key that signed this transaction
|
||||
// The transaction fee will be paid from the corresponding account
|
||||
// (ie the account whose ID is [key].Address())
|
||||
// [key] is non-nil iff this tx is valid
|
||||
key crypto.PublicKey
|
||||
|
||||
// Signature on the UnsignedCreateSubnetTx's byte repr
|
||||
Sig [crypto.SECP256K1RSigLen]byte `serialize:"true"`
|
||||
// ID is this transaction's ID
|
||||
id ids.ID
|
||||
|
||||
// Byte representation of this transaction (including signature)
|
||||
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.
|
||||
// If [tx] is valid, this method sets [tx.key]
|
||||
func (tx *CreateSubnetTx) SyntacticVerify() error {
|
||||
|
@ -70,7 +71,7 @@ func (tx *CreateSubnetTx) SyntacticVerify() error {
|
|||
return errNilTx
|
||||
case tx.key != nil:
|
||||
return nil // Only verify the transaction once
|
||||
case tx.ID.IsZero():
|
||||
case tx.id.IsZero():
|
||||
return errInvalidID
|
||||
case tx.NetworkID != tx.vm.Ctx.NetworkID:
|
||||
return errWrongNetworkID
|
||||
|
@ -108,8 +109,8 @@ func (tx *CreateSubnetTx) SemanticVerify(db database.Database) (func(), error) {
|
|||
}
|
||||
|
||||
for _, subnet := range subnets {
|
||||
if subnet.ID.Equals(tx.ID) {
|
||||
return nil, fmt.Errorf("there is already a subnet with ID %s", tx.ID)
|
||||
if subnet.id.Equals(tx.id) {
|
||||
return nil, fmt.Errorf("there is already a subnet with ID %s", tx.id)
|
||||
}
|
||||
}
|
||||
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
|
||||
onAccept := func() {
|
||||
tx.vm.Validators.PutValidatorSet(tx.ID, validators.NewSet())
|
||||
tx.vm.Validators.PutValidatorSet(tx.id, validators.NewSet())
|
||||
}
|
||||
|
||||
return onAccept, nil
|
||||
|
@ -159,7 +160,7 @@ func (tx *CreateSubnetTx) initialize(vm *VM) error {
|
|||
return err
|
||||
}
|
||||
tx.bytes = txBytes
|
||||
tx.ID = ids.NewID(hashing.ComputeHash256Array(txBytes))
|
||||
tx.id = ids.NewID(hashing.ComputeHash256Array(txBytes))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ func (service *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, respon
|
|||
response.Subnets = make([]APISubnet, len(subnets))
|
||||
for i, subnet := range subnets {
|
||||
response.Subnets[i] = APISubnet{
|
||||
ID: subnet.ID,
|
||||
ID: subnet.id,
|
||||
ControlKeys: subnet.ControlKeys,
|
||||
Threshold: json.Uint16(subnet.Threshold),
|
||||
}
|
||||
|
@ -89,10 +89,10 @@ func (service *Service) GetSubnets(_ *http.Request, args *GetSubnetsArgs, respon
|
|||
idsSet := ids.Set{}
|
||||
idsSet.Add(args.IDs...)
|
||||
for _, subnet := range subnets {
|
||||
if idsSet.Contains(subnet.ID) {
|
||||
if idsSet.Contains(subnet.id) {
|
||||
response.Subnets = append(response.Subnets,
|
||||
APISubnet{
|
||||
ID: subnet.ID,
|
||||
ID: subnet.id,
|
||||
ControlKeys: subnet.ControlKeys,
|
||||
Threshold: json.Uint16(subnet.Threshold),
|
||||
},
|
||||
|
@ -837,15 +837,7 @@ func (service *Service) IssueTx(_ *http.Request, args *IssueTxArgs, response *Is
|
|||
defer service.vm.resetTimer()
|
||||
response.TxID = tx.ID()
|
||||
return nil
|
||||
case *CreateSubnetTx:
|
||||
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:
|
||||
case DecisionTx:
|
||||
if err := tx.initialize(service.vm); err != nil {
|
||||
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()
|
||||
return nil
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
|
||||
// DecisionTx is an operation that can be decided without being proposed
|
||||
type DecisionTx interface {
|
||||
ID() ids.ID
|
||||
|
||||
initialize(vm *VM) error
|
||||
|
||||
// Attempt to verify this transaction with the provided state. The provided
|
||||
|
|
|
@ -211,18 +211,18 @@ func (vm *VM) getSubnets(db database.Database) ([]*CreateSubnetTx, error) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, subnet := range subnets {
|
||||
if subnet.ID.Equals(ID) {
|
||||
if subnet.id.Equals(id) {
|
||||
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
|
||||
|
|
|
@ -318,7 +318,7 @@ func (vm *VM) initSubnets() error {
|
|||
}
|
||||
|
||||
for _, subnet := range subnets {
|
||||
if err := vm.updateValidators(subnet.ID); err != nil {
|
||||
if err := vm.updateValidators(subnet.id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +621,7 @@ func (vm *VM) nextValidatorChangeTime(db database.Database, start bool) time.Tim
|
|||
return earliest
|
||||
}
|
||||
for _, subnet := range subnets {
|
||||
t := vm.nextSubnetValidatorChangeTime(db, subnet.ID, start)
|
||||
t := vm.nextSubnetValidatorChangeTime(db, subnet.id, start)
|
||||
if t.Before(earliest) {
|
||||
earliest = t
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ func defaultVM() *VM {
|
|||
&EventHeap{
|
||||
SortByStartTime: false,
|
||||
},
|
||||
tx.ID,
|
||||
tx.id,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -163,7 +163,7 @@ func defaultVM() *VM {
|
|||
&EventHeap{
|
||||
SortByStartTime: true,
|
||||
},
|
||||
tx.ID,
|
||||
tx.id,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -437,7 +437,7 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
|
|||
uint64(startTime.Unix()),
|
||||
uint64(endTime.Unix()),
|
||||
keys[0].PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[0], testSubnet1ControlKeys[1]},
|
||||
keys[0],
|
||||
|
@ -482,7 +482,7 @@ func TestAddNonDefaultSubnetValidatorAccept(t *testing.T) {
|
|||
commit.Accept() // accept the proposal
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
|
|||
uint64(startTime.Unix()),
|
||||
uint64(endTime.Unix()),
|
||||
keys[0].PublicKey().Address(),
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{testSubnet1ControlKeys[1], testSubnet1ControlKeys[2]},
|
||||
keys[0],
|
||||
|
@ -555,7 +555,7 @@ func TestAddNonDefaultSubnetValidatorReject(t *testing.T) {
|
|||
abort.Accept() // reject the proposal
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -765,7 +765,7 @@ func TestCreateChain(t *testing.T) {
|
|||
|
||||
tx, err := vm.newCreateChainTx(
|
||||
defaultNonce+1,
|
||||
testSubnet1.ID,
|
||||
testSubnet1.id,
|
||||
nil,
|
||||
timestampvm.ID,
|
||||
nil,
|
||||
|
@ -887,7 +887,7 @@ func TestCreateSubnet(t *testing.T) {
|
|||
uint64(startTime.Unix()),
|
||||
uint64(endTime.Unix()),
|
||||
keys[0].PublicKey().Address(),
|
||||
createSubnetTx.ID,
|
||||
createSubnetTx.id,
|
||||
testNetworkID,
|
||||
[]*crypto.PrivateKeySECP256K1R{keys[0]},
|
||||
keys[0],
|
||||
|
@ -937,7 +937,7 @@ func TestCreateSubnet(t *testing.T) {
|
|||
commit.Accept() // add the validator to 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -991,7 +991,7 @@ func TestCreateSubnet(t *testing.T) {
|
|||
|
||||
// Verify validator no longer 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1000,7 +1000,7 @@ func TestCreateSubnet(t *testing.T) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -1050,14 +1050,14 @@ func TestCreateSubnet(t *testing.T) {
|
|||
commit.Accept() // remove validator from current validator set
|
||||
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if pendingValidators.Len() != 0 {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue