8000 fix(types): Add missing JSON tags to `DuplicateVoteEvidence` and `LightClientAttackEvidence` types (backport #3543) by mergify[bot] · Pull Request #3549 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(types): Add missing JSON tags to DuplicateVoteEvidence and LightClientAttackEvidence types (backport #3543) #3549

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[types]` Added missing JSON tags to `DuplicateVoteEvidence` and `LightClientAttackEvidence`
types ([\#3528](https://github.com/cometbft/cometbft/issues/3528))
25 changes: 16 additions & 9 deletions types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type DuplicateVoteEvidence struct {
VoteB *Vote `json:"vote_b"`

// abci specific information
TotalVotingPower int64
ValidatorPower int64
Timestamp time.Time
TotalVotingPower int64 `json:"total_voting_power"`
ValidatorPower int64 `json:"validator_power"`
Timestamp time.Time `json:"timestamp"`
}

var _ Evidence = &DuplicateVoteEvidence{}
Expand Down Expand Up @@ -207,13 +207,20 @@ func DuplicateVoteEvidenceFromProto(pb *cmtproto.DuplicateVoteEvidence) (*Duplic
// and Amnesia. These attacks are exhaustive. You can find a more detailed overview of this at
// cometbft/docs/architecture/adr-047-handling-evidence-from-light-client.md
type LightClientAttackEvidence struct {
ConflictingBlock *LightBlock
CommonHeight int64
ConflictingBlock *LightBlock `json:"conflicting_block"`
CommonHeight int64 `json:"common_height"`

// abci specific information
ByzantineValidators []*Validator // validators in the validator set that misbehaved in creating the conflicting block
TotalVotingPower int64 // total voting power of the validator set at the common height
Timestamp time.Time // timestamp of the block at the common height
// ABCI specific information

// validators in the validator set that misbehaved in creating the conflicting
// block
ByzantineValidators []*Validator `json:"byzantine_validators"`

// total voting power of the validator set at the common height
TotalVotingPower int64 `json:"total_voting_power"`

// timestamp of the block at the common height
Timestamp time.Time `json:"timestamp"`
}

var _ Evidence = &LightClientAttackEvidence{}
Expand Down
21 changes: 21 additions & 0 deletions types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/crypto/tmhash"
cmtjson "github.com/cometbft/cometbft/libs/json"
cmtrand "github.com/cometbft/cometbft/libs/rand"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtversion "github.com/cometbft/cometbft/proto/tendermint/version"
Expand Down Expand Up @@ -310,3 +311,23 @@ func TestEvidenceProto(t *testing.T) {
})
}
}

// Test that the new JSON tags are picked up correctly, see issue #3528.
func TestDuplicateVoteEvidenceJSON(t *testing.T) {
var evidence DuplicateVoteEvidence
js, err := cmtjson.Marshal(evidence)
require.NoError(t, err)

wantJSON := `{"type":"tendermint/DuplicateVoteEvidence","value":{"vote_a":null,"vote_b":null,"total_voting_power":"0",&qu 5E72 ot;validator_power":"0","timestamp":"0001-01-01T00:00:00Z"}}`
assert.Equal(t, wantJSON, string(js))
}

// Test that the new JSON tags are picked up correctly, see issue #3528.
func TestLightClientAttackEvidenceJSON(t *testing.T) {
var evidence LightClientAttackEvidence
js, err := cmtjson.Marshal(evidence)
require.NoError(t, err)

wantJSON := `{"type":"tendermint/LightClientAttackEvidence","value":{"conflicting_block":null,"common_height":"0","byzantine_validators":null,"total_voting_power":"0","timestamp":"0001-01-01T00:00:00Z"}}`
assert.Equal(t, wantJSON, string(js))
}
Loading
0