Skip to content
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

Remove block.Status #593

Merged
merged 7 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.11

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.11.7
github.com/ava-labs/avalanchego v1.11.9-status-removal.2
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -45,7 +45,7 @@ require (
golang.org/x/sys v0.18.0
golang.org/x/text v0.14.0
golang.org/x/time v0.3.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.2
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

Expand Down Expand Up @@ -75,7 +75,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.7 h1:BemCJEa6+f79fzRLdR0+iJAA3v9shOyhVniAKuibFyk=
github.com/ava-labs/avalanchego v1.11.7/go.mod h1:aPYTETkM0KjtC7vFwPO6S8z2L0QTKaXjVUi98pTdNO4=
github.com/ava-labs/avalanchego v1.11.9-status-removal.2 h1:D8gozhuNQpXN1Rc/evjXy2n3OGWb8GvxkgdpBMmRSRE=
github.com/ava-labs/avalanchego v1.11.9-status-removal.2/go.mod h1:Nc85yoe/YatXafBLUesyiUrFT3+bpOrd7UFRFBtzn9A=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -248,8 +248,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand Down Expand Up @@ -963,8 +963,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
13 changes: 0 additions & 13 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ava-labs/coreth/predicate"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
)
Expand Down Expand Up @@ -115,7 +114,6 @@ type Block struct {
id ids.ID
ethBlock *types.Block
vm *VM
status choices.Status
atomicTxs []*Tx
}

Expand Down Expand Up @@ -146,7 +144,6 @@ func (b *Block) Accept(context.Context) error {
// practice to cleanup the batch we were modifying in the case of an error.
defer vm.db.Abort()

b.status = choices.Accepted
log.Debug(fmt.Sprintf("Accepting block %s (%s) at height %d", b.ID().Hex(), b.ID(), b.Height()))

// Call Accept for relevant precompile logs. Note we do this prior to
Expand Down Expand Up @@ -232,7 +229,6 @@ func (b *Block) handlePrecompileAccept(rules params.Rules, sharedMemoryWriter *s
// Reject implements the snowman.Block interface
// If [b] contains an atomic transaction, attempt to re-issue it
func (b *Block) Reject(context.Context) error {
b.status = choices.Rejected
log.Debug(fmt.Sprintf("Rejecting block %s (%s) at height %d", b.ID().Hex(), b.ID(), b.Height()))
for _, tx := range b.atomicTxs {
b.vm.mempool.RemoveTx(tx)
Expand All @@ -251,15 +247,6 @@ func (b *Block) Reject(context.Context) error {
return b.vm.blockChain.Reject(b.ethBlock)
}

// SetStatus implements the InternalBlock interface allowing ChainState
// to set the status on an existing block
func (b *Block) SetStatus(status choices.Status) { b.status = status }

// Status implements the snowman.Block interface
func (b *Block) Status() choices.Status {
return b.status
}

// Parent implements the snowman.Block interface
func (b *Block) Parent() ids.ID {
return ids.ID(b.ethBlock.ParentHash())
Expand Down
2 changes: 0 additions & 2 deletions plugin/evm/syncervm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/vms/components/chain"
Expand Down Expand Up @@ -336,7 +335,6 @@ func (client *stateSyncerClient) finishSync() error {
return fmt.Errorf("could not convert block(%T) to evm.Block", stateBlock)
}

evmBlock.SetStatus(choices.Accepted)
block := evmBlock.ethBlock

if block.Hash() != client.syncSummary.BlockHash {
Expand Down
2 changes: 0 additions & 2 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
Expand Down Expand Up @@ -351,7 +350,6 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest, numBlocks int) *s
require.NoError(err)
internalBlock, err := serverVM.parseBlock(context.Background(), blockBytes)
require.NoError(err)
internalBlock.(*Block).SetStatus(choices.Accepted)
require.NoError(serverVM.State.SetLastAcceptedBlock(internalBlock))

// patch syncableInterval for test
Expand Down
51 changes: 39 additions & 12 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import (
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
Expand Down Expand Up @@ -593,7 +592,15 @@ func (vm *VM) Initialize(
for i, hexMsg := range vm.config.WarpOffChainMessages {
offchainWarpMessages[i] = []byte(hexMsg)
}
vm.warpBackend, err = warp.NewBackend(vm.ctx.NetworkID, vm.ctx.ChainID, vm.ctx.WarpSigner, vm, vm.warpDB, warpSignatureCacheSize, offchainWarpMessages)
vm.warpBackend, err = warp.NewBackend(
vm.ctx.NetworkID,
vm.ctx.ChainID,
vm.ctx.WarpSigner,
vm,
vm.warpDB,
warpSignatureCacheSize,
offchainWarpMessages,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -772,14 +779,12 @@ func (vm *VM) initChainState(lastAcceptedBlock *types.Block) error {
if err != nil {
return fmt.Errorf("failed to create block wrapper for the last accepted block: %w", err)
}
block.status = choices.Accepted

config := &chain.Config{
DecidedCacheSize: decidedCacheSize,
MissingCacheSize: missingCacheSize,
UnverifiedCacheSize: unverifiedCacheSize,
BytesToIDCacheSize: bytesToIDCacheSize,
GetBlockIDAtHeight: vm.GetBlockIDAtHeight,
GetBlock: vm.getBlock,
UnmarshalBlock: vm.parseBlock,
BuildBlock: vm.buildBlock,
Expand Down Expand Up @@ -1378,6 +1383,33 @@ func (vm *VM) getBlock(_ context.Context, id ids.ID) (snowman.Block, error) {
return vm.newBlock(ethBlock)
}

// GetAcceptedBlock attempts to retrieve block [blkID] from the VM. This method
// only returns accepted blocks.
func (vm *VM) GetAcceptedBlock(ctx context.Context, blkID ids.ID) (snowman.Block, error) {
blk, err := vm.GetBlock(ctx, blkID)
if err != nil {
return nil, err
}

lastAcceptedBlock := vm.LastAcceptedBlock()
height := blk.Height()
if lastAcceptedBlock.Height() < height {
// The provided block is not decided.
return nil, database.ErrNotFound
}

acceptedBlkID, err := vm.GetBlockIDAtHeight(ctx, height)
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

if acceptedBlkID != blkID {
// The provided block is not accepted.
return nil, database.ErrNotFound
}
return blk, nil
}

// SetPreference sets what the current tail of the chain is
func (vm *VM) SetPreference(ctx context.Context, blkID ids.ID) error {
// Since each internal handler used by [vm.State] always returns a block
Expand Down Expand Up @@ -1507,7 +1539,9 @@ func (vm *VM) CreateStaticHandlers(context.Context) (map[string]http.Handler, er
// accepted, then nil will be returned immediately.
// If the ancestry of [ancestor] cannot be fetched, then [errRejectedParent] may be returned.
func (vm *VM) conflicts(inputs set.Set[ids.ID], ancestor *Block) error {
for ancestor.Status() != choices.Accepted {
lastAcceptedBlock := vm.LastAcceptedBlock()
lastAcceptedHeight := lastAcceptedBlock.Height()
for ancestor.Height() > lastAcceptedHeight {
// If any of the atomic transactions in the ancestor conflict with [inputs]
// return an error.
for _, atomicTx := range ancestor.atomicTxs {
Expand All @@ -1529,10 +1563,6 @@ func (vm *VM) conflicts(inputs set.Set[ids.ID], ancestor *Block) error {
if err != nil {
return errRejectedParent
}

if blkStatus := nextAncestorIntf.Status(); blkStatus == choices.Unknown || blkStatus == choices.Rejected {
return errRejectedParent
}
nextAncestor, ok := nextAncestorIntf.(*Block)
if !ok {
return fmt.Errorf("ancestor block %s had unexpected type %T", nextAncestor.ID(), nextAncestorIntf)
Expand Down Expand Up @@ -1662,9 +1692,6 @@ func (vm *VM) verifyTxs(txs []*Tx, parentHash common.Hash, baseFee *big.Int, hei
if err != nil {
return errRejectedParent
}
if blkStatus := ancestorInf.Status(); blkStatus == choices.Unknown || blkStatus == choices.Rejected {
return errRejectedParent
}
ancestor, ok := ancestorInf.(*Block)
if !ok {
return fmt.Errorf("expected parent block %s, to be *Block but is %T", ancestor.ID(), ancestorInf)
Expand Down
Loading
Loading