strip extensions in blocksync

This commit is contained in:
William Banfield
2022-05-16 19:20:08 -04:00
parent 44f1f045e2
commit 93ea3d0b7d
18 changed files with 55 additions and 44 deletions
+2
View File
@@ -560,6 +560,8 @@ func (r *Reactor) poolRoutine(ctx context.Context, stateSynced bool, blockSyncCh
if err == nil && state.ConsensusParams.ABCI.VoteExtensionsEnabled(extCommit.Height) {
// if vote extensions were required at this height, ensure they exist.
err = extCommit.EnsureExtensions()
} else if err == nil && !state.ConsensusParams.ABCI.VoteExtensionsEnabled(extCommit.Height) {
extCommit.StripExtensions()
}
// If either of the checks failed we log the error and request for a new block
// at that height
+1 -1
View File
@@ -155,7 +155,7 @@ func (rts *reactorTestSuite) addNode(
for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {
lastExtCommit = seenExtCommit.Clone()
thisBlock := sf.MakeBlock(state, blockHeight, lastExtCommit.StripExtensions())
thisBlock := sf.MakeBlock(state, blockHeight, lastExtCommit.ToCommit())
thisParts, err := thisBlock.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
+2 -2
View File
@@ -1208,10 +1208,10 @@ func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSe
}
func (bs *mockBlockStore) LoadBlockCommit(height int64) *types.Commit {
return bs.extCommits[height-1].StripExtensions()
return bs.extCommits[height-1].ToCommit()
}
func (bs *mockBlockStore) LoadSeenCommit() *types.Commit {
return bs.extCommits[len(bs.extCommits)-1].StripExtensions()
return bs.extCommits[len(bs.extCommits)-1].ToCommit()
}
func (bs *mockBlockStore) LoadBlockExtendedCommit(height int64) *types.ExtendedCommit {
return bs.extCommits[height-1]
+2 -2
View File
@@ -250,7 +250,7 @@ func TestEvidencePoolUpdate(t *testing.T) {
)
require.NoError(t, err)
lastExtCommit := makeExtCommit(height, val.PrivKey.PubKey().Address())
block := types.MakeBlock(height+1, []types.Tx{}, lastExtCommit.StripExtensions(), []types.Evidence{ev})
block := types.MakeBlock(height+1, []types.Tx{}, lastExtCommit.ToCommit(), []types.Evidence{ev})
// update state (partially)
state.LastBlockHeight = height + 1
@@ -569,7 +569,7 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo
for i := int64(1); i <= state.LastBlockHeight; i++ {
lastCommit := makeExtCommit(i-1, valAddr)
block := sf.MakeBlock(state, i, lastCommit.StripExtensions())
block := sf.MakeBlock(state, i, lastCommit.ToCommit())
block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute)
block.Header.Version = version.Consensus{Block: version.BlockProtocol, App: 1}
+6 -6
View File
@@ -236,7 +236,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) {
voteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals)
extCommit, err := factory.MakeExtendedCommit(ctx, blockID, 10, 1, voteSet, conflictingPrivVals[:4], defaultEvidenceTime)
require.NoError(t, err)
commit := extCommit.StripExtensions()
commit := extCommit.ToCommit()
ev := &types.LightClientAttackEvidence{
ConflictingBlock: &types.LightBlock{
@@ -257,7 +257,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) {
trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, 10, 1,
trustedVoteSet, conflictingPrivVals, defaultEvidenceTime)
require.NoError(t, err)
trustedCommit := trustedExtCommit.StripExtensions()
trustedCommit := trustedExtCommit.ToCommit()
trustedSignedHeader := &types.SignedHeader{
Header: trustedHeader,
@@ -339,7 +339,7 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) {
voteSet := types.NewVoteSet(evidenceChainID, height, 0, tmproto.SignedMsgType(2), conflictingVals)
extCommit, err := factory.MakeExtendedCommit(ctx, blockID, height, 0, voteSet, conflictingPrivVals, defaultEvidenceTime)
require.NoError(t, err)
commit := extCommit.StripExtensions()
commit := extCommit.ToCommit()
ev := &types.LightClientAttackEvidence{
ConflictingBlock: &types.LightBlock{
@@ -360,7 +360,7 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) {
trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, height, 1,
trustedVoteSet, conflictingPrivVals, defaultEvidenceTime)
require.NoError(t, err)
trustedCommit := trustedExtCommit.StripExtensions()
trustedCommit := trustedExtCommit.ToCommit()
trustedSignedHeader := &types.SignedHeader{
Header: trustedHeader,
@@ -556,7 +556,7 @@ func makeLunaticEvidence(
voteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), conflictingVals)
extCommit, err := factory.MakeExtendedCommit(ctx, blockID, height, 1, voteSet, conflictingPrivVals, defaultEvidenceTime)
require.NoError(t, err)
commit := extCommit.StripExtensions()
commit := extCommit.ToCommit()
ev = &types.LightClientAttackEvidence{
ConflictingBlock: &types.LightBlock{
@@ -585,7 +585,7 @@ func makeLunaticEvidence(
trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), trustedVals)
trustedExtCommit, err := factory.MakeExtendedCommit(ctx, trustedBlockID, height, 1, trustedVoteSet, privVals, defaultEvidenceTime)
require.NoError(t, err)
trustedCommit := trustedExtCommit.StripExtensions()
trustedCommit := trustedExtCommit.ToCommit()
trusted = &types.LightBlock{
SignedHeader: &types.SignedHeader{
+1 -1
View File
@@ -101,7 +101,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
maxDataBytes := types.MaxDataBytes(maxBytes, evSize, state.Validators.Size())
txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
commit := lastExtCommit.StripExtensions()
commit := lastExtCommit.ToCommit()
block := state.MakeBlock(height, txs, commit, evidence, proposerAddr)
rpp, err := blockExec.appClient.PrepareProposal(
ctx,
+1 -1
View File
@@ -140,7 +140,7 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) {
}
// block for height 2
block := sf.MakeBlock(state, 2, lastCommit.StripExtensions())
block := sf.MakeBlock(state, 2, lastCommit.ToCommit())
bps, err := block.MakePartSet(testPartSize)
require.NoError(t, err)
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()}
+3 -3
View File
@@ -124,7 +124,7 @@ func TestValidateBlockHeader(t *testing.T) {
*/
state, _, lastExtCommit = makeAndCommitGoodBlock(ctx, t,
state, height, lastCommit, state.Validators.GetProposer().Address, blockExec, privVals, nil)
lastCommit = lastExtCommit.StripExtensions()
lastCommit = lastExtCommit.ToCommit()
}
nextHeight := validationTestsStopHeight
@@ -234,7 +234,7 @@ func TestValidateBlockCommit(t *testing.T) {
privVals,
nil,
)
lastCommit = lastExtCommit.StripExtensions()
lastCommit = lastExtCommit.ToCommit()
/*
wrongSigsCommit is fine except for the extra bad precommit
@@ -384,7 +384,7 @@ func TestValidateBlockEvidence(t *testing.T) {
privVals,
evidence,
)
lastCommit = lastExtCommit.StripExtensions()
lastCommit = lastExtCommit.ToCommit()
}
}
+1 -1
View File
@@ -861,7 +861,7 @@ func mockLB(ctx context.Context, t *testing.T, height int64, time time.Time, las
return nextVals, nextPrivVals, &types.LightBlock{
SignedHeader: &types.SignedHeader{
Header: header,
Commit: extCommit.StripExtensions(),
Commit: extCommit.ToCommit(),
},
ValidatorSet: currentVals,
}
+1 -1
View File
@@ -518,7 +518,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
}
// Save seen commit (seen +2/3 precommits for block)
pbsc := seenCommit.StripExtensions().ToProto()
pbsc := seenCommit.ToCommit().ToProto()
seenCommitBytes := mustEncode(pbsc)
if err := batch.Set(seenCommitKey(), seenCommitBytes); err != nil {
panic(err)
+4 -4
View File
@@ -107,7 +107,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
}
// End of setup, test data
commitAtH10 := makeTestExtCommit(10, tmtime.Now()).StripExtensions()
commitAtH10 := makeTestExtCommit(10, tmtime.Now()).ToCommit()
tuples := []struct {
block *types.Block
parts *types.PartSet
@@ -140,7 +140,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
ChainID: "block_test",
Time: tmtime.Now(),
ProposerAddress: tmrand.Bytes(crypto.AddressSize)},
makeTestExtCommit(5, tmtime.Now()).StripExtensions(),
makeTestExtCommit(5, tmtime.Now()).ToCommit(),
),
parts: validPartSet,
seenCommit: makeTestExtCommit(5, tmtime.Now()),
@@ -518,7 +518,7 @@ func TestSeenAndCanonicalCommit(t *testing.T) {
// produce a few blocks and check that the correct seen and cannoncial commits
// are persisted.
for h := int64(3); h <= 5; h++ {
blockCommit := makeTestExtCommit(h-1, tmtime.Now()).StripExtensions()
blockCommit := makeTestExtCommit(h-1, tmtime.Now()).ToCommit()
block := factory.MakeBlock(state, h, blockCommit)
partSet, err := block.MakePartSet(2)
require.NoError(t, err)
@@ -527,7 +527,7 @@ func TestSeenAndCanonicalCommit(t *testing.T) {
c3 := store.LoadSeenCommit()
require.NotNil(t, c3)
require.Equal(t, h, c3.Height)
require.Equal(t, seenCommit.StripExtensions().Hash(), c3.Hash())
require.Equal(t, seenCommit.ToCommit().Hash(), c3.Hash())
c5 := store.LoadBlockCommit(h)
require.Nil(t, c5)
c6 := store.LoadBlockCommit(h - 1)