diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index ceea225f26..103dfa8c5e 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -894,8 +894,8 @@ func (fb *filterBackend) SubscribeAcceptedTransactionEvent(ch chan<- core.NewTxs return fb.bc.SubscribeAcceptedTransactionEvent(ch) } -func (fb *filterBackend) GetVMConfig() *vm.Config { - return fb.bc.GetVMConfig() +func (fb *filterBackend) IsAllowUnfinalizedQueries() bool { + return false } func (fb *filterBackend) LastAcceptedBlock() *types.Block { diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 1752669d0d..ef119ba26a 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -40,9 +40,6 @@ type Config struct { NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls) EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages ExtraEips []int // Additional EIPS that are to be enabled - - // AllowUnfinalizedQueries allow unfinalized queries - AllowUnfinalizedQueries bool } // ScopeContext contains the things that are per-call, such as stack and memory, diff --git a/eth/api_backend.go b/eth/api_backend.go index f87c256803..c6804fb000 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -58,6 +58,7 @@ type EthAPIBackend struct { extRPCEnabled bool allowUnprotectedTxs bool allowUnprotectedTxHashes map[common.Hash]struct{} // Invariant: read-only after creation. + allowUnfinalizedQueries bool eth *Ethereum gpo *gasprice.Oracle } @@ -67,8 +68,12 @@ func (b *EthAPIBackend) ChainConfig() *params.ChainConfig { return b.eth.blockchain.Config() } -func (b *EthAPIBackend) GetVMConfig() *vm.Config { - return b.eth.blockchain.GetVMConfig() +func (b *EthAPIBackend) IsAllowUnfinalizedQueries() bool { + return b.allowUnfinalizedQueries +} + +func (b *EthAPIBackend) SetAllowUnfinalizedQueries(allow bool) { + b.allowUnfinalizedQueries = allow } func (b *EthAPIBackend) CurrentBlock() *types.Header { @@ -90,7 +95,7 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb return acceptedBlock.Header(), nil } - if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil { + if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil { if number.Int64() > acceptedBlock.Number().Int64() { return nil, ErrUnfinalizedData } @@ -118,7 +123,7 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty } acceptedBlock := b.eth.LastAcceptedBlock() - if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil { + if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil { if header.Number.Cmp(acceptedBlock.Number()) > 0 { return nil, ErrUnfinalizedData } @@ -154,7 +159,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe return acceptedBlock, nil } - if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil { + if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil { if number.Int64() > acceptedBlock.Number().Int64() { return nil, ErrUnfinalizedData } @@ -179,7 +184,7 @@ func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*typ } acceptedBlock := b.eth.LastAcceptedBlock() - if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil { + if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil { if number.Cmp(acceptedBlock.Number()) > 0 { return nil, ErrUnfinalizedData } @@ -350,7 +355,7 @@ func (b *EthAPIBackend) GetTransaction(ctx context.Context, txHash common.Hash) // expectations with clients (expect an empty response when a transaction // does not exist). acceptedBlock := b.eth.LastAcceptedBlock() - if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil && tx != nil { + if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil && tx != nil { if blockNumber > acceptedBlock.NumberU64() { return nil, common.Hash{}, 0, 0, nil } diff --git a/eth/backend.go b/eth/backend.go index d2d8e255a5..77606b6589 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -181,7 +181,6 @@ func New( var ( vmConfig = vm.Config{ EnablePreimageRecording: config.EnablePreimageRecording, - AllowUnfinalizedQueries: config.AllowUnfinalizedQueries, } cacheConfig = &core.CacheConfig{ TrieCleanLimit: config.TrieCleanCache, @@ -241,6 +240,7 @@ func New( extRPCEnabled: stack.Config().ExtRPCEnabled(), allowUnprotectedTxs: config.AllowUnprotectedTxs, allowUnprotectedTxHashes: allowUnprotectedTxHashes, + allowUnfinalizedQueries: config.AllowUnfinalizedQueries, eth: eth, } if config.AllowUnprotectedTxs { diff --git a/eth/filters/api.go b/eth/filters/api.go index 911439935d..a4412cd975 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -245,7 +245,7 @@ func (api *FilterAPI) NewBlockFilter() rpc.ID { headerSub *Subscription ) - if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries { + if api.sys.backend.IsAllowUnfinalizedQueries() { headerSub = api.events.SubscribeNewHeads(headers) } else { headerSub = api.events.SubscribeAcceptedHeads(headers) @@ -291,7 +291,7 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) { headersSub event.Subscription ) - if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries { + if api.sys.backend.IsAllowUnfinalizedQueries() { headersSub = api.events.SubscribeNewHeads(headers) } else { headersSub = api.events.SubscribeAcceptedHeads(headers) @@ -328,7 +328,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc err error ) - if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries { + if api.sys.backend.IsAllowUnfinalizedQueries() { logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), matchedLogs) if err != nil { return nil, err @@ -383,7 +383,7 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) { err error ) - if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries { + if api.sys.backend.IsAllowUnfinalizedQueries() { logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), logs) if err != nil { return rpc.ID(""), err diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 0bcd0a7b5f..63a3fd3d04 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -54,7 +54,7 @@ type Filter struct { // NewRangeFilter creates a new filter which uses a bloom filter on blocks to // figure out whether a particular block is interesting or not. func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash) (*Filter, error) { - allowUnfinalizedQueries := sys.backend.GetVMConfig().AllowUnfinalizedQueries + allowUnfinalizedQueries := sys.backend.IsAllowUnfinalizedQueries() acceptedBlock := sys.backend.LastAcceptedBlock() // Flatten the address and topic filter clauses into a single bloombits filter diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 865766d29d..4ebd672d47 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -38,7 +38,6 @@ import ( "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/core/bloombits" "github.com/ava-labs/subnet-evm/core/types" - "github.com/ava-labs/subnet-evm/core/vm" "github.com/ava-labs/subnet-evm/interfaces" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/rpc" @@ -85,7 +84,7 @@ type Backend interface { ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) // Added to the backend interface to support limiting of logs requests - GetVMConfig() *vm.Config + IsAllowUnfinalizedQueries() bool LastAcceptedBlock() *types.Block GetMaxBlocksPerRequest() int64 } diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 6f49eabb27..962cfc6967 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -42,7 +42,6 @@ import ( "github.com/ava-labs/subnet-evm/core/bloombits" "github.com/ava-labs/subnet-evm/core/rawdb" "github.com/ava-labs/subnet-evm/core/types" - "github.com/ava-labs/subnet-evm/core/vm" "github.com/ava-labs/subnet-evm/interfaces" "github.com/ava-labs/subnet-evm/internal/ethapi" "github.com/ava-labs/subnet-evm/params" @@ -78,8 +77,8 @@ func (b *testBackend) ChainDb() ethdb.Database { return b.db } -func (b *testBackend) GetVMConfig() *vm.Config { - return &vm.Config{AllowUnfinalizedQueries: true} +func (b *testBackend) IsAllowUnfinalizedQueries() bool { + return true } func (b *testBackend) GetMaxBlocksPerRequest() int64 { diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 0f2c4571c0..c5620c7f92 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -1070,7 +1070,7 @@ func TestNonCanonicalAccept(t *testing.T) { t.Fatal(err) } - vm1.blockChain.GetVMConfig().AllowUnfinalizedQueries = true + vm1.eth.APIBackend.SetAllowUnfinalizedQueries(true) blkBHeight := vm1BlkB.Height() blkBHash := vm1BlkB.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash() @@ -1241,7 +1241,7 @@ func TestStickyPreference(t *testing.T) { t.Fatal(err) } - vm1.blockChain.GetVMConfig().AllowUnfinalizedQueries = true + vm1.eth.APIBackend.SetAllowUnfinalizedQueries(true) blkBHeight := vm1BlkB.Height() blkBHash := vm1BlkB.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash() @@ -1940,7 +1940,7 @@ func TestLastAcceptedBlockNumberAllow(t *testing.T) { blkHeight := blk.Height() blkHash := blk.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash() - vm.blockChain.GetVMConfig().AllowUnfinalizedQueries = true + vm.eth.APIBackend.SetAllowUnfinalizedQueries(true) ctx := context.Background() b, err := vm.eth.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(blkHeight)) @@ -1951,7 +1951,7 @@ func TestLastAcceptedBlockNumberAllow(t *testing.T) { t.Fatalf("expected block at %d to have hash %s but got %s", blkHeight, blkHash.Hex(), b.Hash().Hex()) } - vm.blockChain.GetVMConfig().AllowUnfinalizedQueries = false + vm.eth.APIBackend.SetAllowUnfinalizedQueries(false) _, err = vm.eth.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(blkHeight)) if !errors.Is(err, eth.ErrUnfinalizedData) {