Skip to content

stop persisting rejected blocks on P-chain #1696

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 10 commits into from
Jul 11, 2023
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
3 changes: 1 addition & 2 deletions vms/platformvm/blocks/executor/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
"github.com/ava-labs/avalanchego/vms/platformvm/metrics"
Expand Down Expand Up @@ -286,7 +285,7 @@ func (a *acceptor) commonAccept(b blocks.Block) error {
a.backend.lastAccepted = blkID
a.state.SetLastAccepted(blkID)
a.state.SetHeight(b.Height())
a.state.AddStatelessBlock(b, choices.Accepted)
a.state.AddStatelessBlock(b)
a.validators.OnAcceptedBlockID(blkID)
return nil
}
25 changes: 12 additions & 13 deletions vms/platformvm/blocks/executor/acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
// We should error after [commonAccept] is called.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)

err = acceptor.ApricotAtomicBlock(blk)
require.ErrorIs(err, errMissingBlockState)
Expand Down Expand Up @@ -148,7 +147,7 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
// Set expected calls on dependencies.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)
batch := database.NewMockBatch(ctrl)
s.EXPECT().CommitBatch().Return(batch, nil).Times(1)
s.EXPECT().Abort().Times(1)
Expand Down Expand Up @@ -203,7 +202,7 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
// We should error after [commonAccept] is called.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)

err = acceptor.BanffStandardBlock(blk)
require.ErrorIs(err, errMissingBlockState)
Expand Down Expand Up @@ -238,7 +237,7 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
// Set expected calls on dependencies.
s.EXPECT().SetLastAccepted(blk.ID()).Times(1)
s.EXPECT().SetHeight(blk.Height()).Times(1)
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1)
s.EXPECT().AddStatelessBlock(blk).Times(1)
batch := database.NewMockBatch(ctrl)
s.EXPECT().CommitBatch().Return(batch, nil).Times(1)
s.EXPECT().Abort().Times(1)
Expand Down Expand Up @@ -304,11 +303,11 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
s.EXPECT().SetLastAccepted(parentID).Times(1),
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),
)

err = acceptor.ApricotCommitBlock(blk)
Expand All @@ -328,11 +327,11 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
s.EXPECT().SetLastAccepted(parentID).Times(1),
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),

onAcceptState.EXPECT().Apply(s).Times(1),
s.EXPECT().Commit().Return(nil).Times(1),
Expand Down Expand Up @@ -396,11 +395,11 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
s.EXPECT().SetLastAccepted(parentID).Times(1),
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),
)

err = acceptor.ApricotAbortBlock(blk)
Expand All @@ -421,11 +420,11 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
s.EXPECT().SetLastAccepted(parentID).Times(1),
parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1),
s.EXPECT().SetHeight(blk.Height()-1).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1),

s.EXPECT().SetLastAccepted(blkID).Times(1),
s.EXPECT().SetHeight(blk.Height()).Times(1),
s.EXPECT().AddStatelessBlock(blk, choices.Accepted).Times(1),
s.EXPECT().AddStatelessBlock(blk).Times(1),

onAcceptState.EXPECT().Apply(s).Times(1),
s.EXPECT().Commit().Return(nil).Times(1),
Expand Down
4 changes: 1 addition & 3 deletions vms/platformvm/blocks/executor/rejector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package executor
import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
)

Expand Down Expand Up @@ -78,6 +77,5 @@ func (r *rejector) rejectBlock(b blocks.Block, blockType string) error {
}
}

r.state.AddStatelessBlock(b, choices.Rejected)
return r.state.Commit()
return nil
}
5 changes: 0 additions & 5 deletions vms/platformvm/blocks/executor/rejector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm/blocks"
Expand Down Expand Up @@ -142,10 +141,6 @@ func TestRejectBlock(t *testing.T) {
for _, tx := range blk.Txs() {
mempool.EXPECT().Add(tx).Return(nil).Times(1)
}
gomock.InOrder(
state.EXPECT().AddStatelessBlock(blk, choices.Rejected).Times(1),
state.EXPECT().Commit().Return(nil).Times(1),
)

require.NoError(tt.rejectFunc(rejector, blk))
// Make sure block and its parent are removed from the state map.
Expand Down
8 changes: 4 additions & 4 deletions vms/platformvm/state/mock_state.go

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

10 changes: 6 additions & 4 deletions vms/platformvm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ type State interface {
SetLastAccepted(blkID ids.ID)

GetStatelessBlock(blockID ids.ID) (blocks.Block, choices.Status, error)
AddStatelessBlock(block blocks.Block, status choices.Status)

// Invariant: [block] is an accepted block.
AddStatelessBlock(block blocks.Block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we rename this AddStatelessAcceptedBlock for clarify? Maybe it's too long of name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this change would be reverted when we remove status from GetStatelessBlock


// ValidatorSet adds all the validators and delegators of [subnetID] into
// [vdrs].
Expand Down Expand Up @@ -1023,7 +1025,7 @@ func (s *state) syncGenesis(genesisBlk blocks.Block, genesis *genesis.State) err
s.SetLastAccepted(genesisBlkID)
s.SetTimestamp(time.Unix(int64(genesis.Timestamp), 0))
s.SetCurrentSupply(constants.PrimaryNetworkID, genesis.InitialSupply)
s.AddStatelessBlock(genesisBlk, choices.Accepted)
s.AddStatelessBlock(genesisBlk)

// Persist UTXOs that exist at genesis
for _, utxo := range genesis.UTXOs {
Expand Down Expand Up @@ -1486,11 +1488,11 @@ func (s *state) init(genesisBytes []byte) error {
return s.Commit()
}

func (s *state) AddStatelessBlock(block blocks.Block, status choices.Status) {
func (s *state) AddStatelessBlock(block blocks.Block) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we err if the block status is not actually accepted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have that information here.

s.addedBlocks[block.ID()] = stateBlk{
Blk: block,
Bytes: block.Bytes(),
Status: status,
Status: choices.Accepted,
}
}

Expand Down