Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
feat: add challenger address to validators (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Mar 14, 2023
1 parent b3f4927 commit 337f92c
Show file tree
Hide file tree
Showing 9 changed files with 469 additions and 258 deletions.
418 changes: 236 additions & 182 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,11 @@ message Validator {

// ValidatorUpdate
message ValidatorUpdate {
tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false];
int64 power = 2;
bytes relayer_bls_key = 3;
bytes relayer_address = 4;
tendermint.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false];
int64 power = 2;
bytes relayer_bls_key = 3;
bytes relayer_address = 4;
bytes challenger_address = 5;
}

// VoteInfo
Expand Down
182 changes: 145 additions & 37 deletions proto/tendermint/types/validator.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions proto/tendermint/types/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ message ValidatorSet {
}

message Validator {
bytes address = 1;
tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false];
int64 voting_power = 3;
int64 proposer_priority = 4;
bytes relayer_bls_key = 5;
bytes relayer_address = 6;
bytes address = 1;
tendermint.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false];
int64 voting_power = 3;
int64 proposer_priority = 4;
bytes relayer_bls_key = 5;
bytes relayer_address = 6;
bytes challenger_address = 7;
}

message SimpleValidator {
tendermint.crypto.PublicKey pub_key = 1;
int64 voting_power = 2;
bytes relayer_bls_key = 3;
bytes relayer_address = 4;
tendermint.crypto.PublicKey pub_key = 1;
int64 voting_power = 2;
bytes relayer_bls_key = 3;
bytes relayer_address = 4;
bytes challenger_address = 5;
}
23 changes: 19 additions & 4 deletions state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ func TestValidateValidatorUpdates(t *testing.T) {
defaultValidatorParams,
false,
},
{
"updating a validator with challenger address is OK",
[]abci.ValidatorUpdate{{PubKey: pk1, Power: 20, ChallengerAddress: ([]byte)("relayer")}},
defaultValidatorParams,
false,
},
{
"removing a validator is OK",
[]abci.ValidatorUpdate{{PubKey: pk2, Power: 0}},
Expand Down Expand Up @@ -298,9 +304,11 @@ func TestUpdateValidators(t *testing.T) {
// updated validator with mock relayer bls public key and relayer address
updated := types.NewValidator(pubkey1, 20)
blsPubKey := ed25519.GenPrivKey().PubKey().Bytes()
relayer := ed25519.GenPrivKey().PubKey().Address().Bytes()
updated.SetRelayerBlsKey(blsPubKey)
relayer := ed25519.GenPrivKey().PubKey().Address().Bytes()
updated.SetRelayerAddress(relayer)
challenger := ed25519.GenPrivKey().PubKey().Address().Bytes()
updated.SetChallengerAddress(challenger)

testCases := []struct {
name string
Expand Down Expand Up @@ -340,9 +348,10 @@ func TestUpdateValidators(t *testing.T) {
true,
},
{
"updating a validator with relayer bls public key and address is OK",
"updating a validator with relayer bls public key, relayer and challenger address is OK",
types.NewValidatorSet([]*types.Validator{val1}),
[]abci.ValidatorUpdate{{PubKey: pk, Power: 20, RelayerBlsKey: blsPubKey, RelayerAddress: relayer}},
[]abci.ValidatorUpdate{{PubKey: pk, Power: 20,
RelayerBlsKey: blsPubKey, RelayerAddress: relayer, ChallengerAddress: challenger}},
types.NewValidatorSet([]*types.Validator{updated}),
false,
},
Expand All @@ -364,11 +373,13 @@ func TestUpdateValidators(t *testing.T) {
assert.Equal(t, tc.resultingSet.Validators[0].Address, tc.currentSet.Validators[0].Address)
assert.Equal(t, tc.resultingSet.Validators[0].RelayerBlsKey, tc.currentSet.Validators[0].RelayerBlsKey)
assert.Equal(t, tc.resultingSet.Validators[0].RelayerAddress, tc.currentSet.Validators[0].RelayerAddress)
assert.Equal(t, tc.resultingSet.Validators[0].ChallengerAddress, tc.currentSet.Validators[0].ChallengerAddress)

if tc.resultingSet.Size() > 1 {
assert.Equal(t, tc.resultingSet.Validators[1].Address, tc.currentSet.Validators[1].Address)
assert.Equal(t, tc.resultingSet.Validators[1].RelayerBlsKey, tc.currentSet.Validators[1].RelayerBlsKey)
assert.Equal(t, tc.resultingSet.Validators[1].RelayerAddress, tc.currentSet.Validators[1].RelayerAddress)
assert.Equal(t, tc.resultingSet.Validators[1].ChallengerAddress, tc.currentSet.Validators[1].ChallengerAddress)
}

}
Expand Down Expand Up @@ -425,10 +436,12 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
currentValPower := currentVal.VotingPower
blsPubKey := ed25519.GenPrivKey().PubKey().Bytes()
relayer := ed25519.GenPrivKey().PubKey().Address().Bytes()
challenger := ed25519.GenPrivKey().PubKey().Address().Bytes()

app.ValidatorUpdates = []abci.ValidatorUpdate{
{PubKey: pk, Power: 10}, // add a new validator
{PubKey: currentValPk, Power: currentValPower, RelayerBlsKey: blsPubKey, RelayerAddress: relayer}, // updating a validator's relayer pub key and address
{PubKey: currentValPk, Power: currentValPower,
RelayerBlsKey: blsPubKey, RelayerAddress: relayer, ChallengerAddress: challenger}, // updating a validator's relayer pub key and address
}

state, _, err = blockExec.ApplyBlock(state, blockID, block)
Expand All @@ -448,6 +461,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
}
assert.Equal(t, blsPubKey, val.RelayerBlsKey)
assert.Equal(t, relayer, val.RelayerAddress)
assert.Equal(t, challenger, val.ChallengerAddress)
}

// test we threw an event
Expand All @@ -461,6 +475,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) {

assert.Equal(t, blsPubKey, event.ValidatorUpdates[1].RelayerBlsKey)
assert.EqualValues(t, relayer, event.ValidatorUpdates[1].RelayerAddress)
assert.EqualValues(t, challenger, event.ValidatorUpdates[1].ChallengerAddress)
}
case <-updatesSub.Cancelled():
t.Fatalf("updatesSub was cancelled (reason: %v)", updatesSub.Err())
Expand Down
1 change: 1 addition & 0 deletions types/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error)
updated := NewValidator(pub, v.Power)
updated.SetRelayerBlsKey(v.RelayerBlsKey)
updated.SetRelayerAddress(v.RelayerAddress)
updated.SetChallengerAddress(v.ChallengerAddress)
tmVals[i] = updated
}
return tmVals, nil
Expand Down
Loading

0 comments on commit 337f92c

Please sign in to comment.