Skip to content

Commit bebdd56

Browse files
author
Darioush Jalali
authored
refactor: move AllowUnfinalizedQueries out of vm.Config (#443)
* refactor: move AllowUnfinalizedQueries out of vm.Config * fix comment * review naming suggestion * Revert "fix comment" This reverts commit 323f1cf.
1 parent 8f40304 commit bebdd56

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ func (fb *filterBackend) SubscribeAcceptedTransactionEvent(ch chan<- core.NewTxs
893893
return fb.bc.SubscribeAcceptedTransactionEvent(ch)
894894
}
895895

896-
func (fb *filterBackend) GetVMConfig() *vm.Config {
897-
return fb.bc.GetVMConfig()
896+
func (fb *filterBackend) IsAllowUnfinalizedQueries() bool {
897+
return false
898898
}
899899

900900
func (fb *filterBackend) LastAcceptedBlock() *types.Block {

core/vm/interpreter.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ type Config struct {
4545
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
4646
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
4747
ExtraEips []int // Additional EIPS that are to be enabled
48-
49-
// AllowUnfinalizedQueries allow unfinalized queries
50-
AllowUnfinalizedQueries bool
5148
}
5249

5350
// ScopeContext contains the things that are per-call, such as stack and memory,

eth/api_backend.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type EthAPIBackend struct {
5757
extRPCEnabled bool
5858
allowUnprotectedTxs bool
5959
allowUnprotectedTxHashes map[common.Hash]struct{} // Invariant: read-only after creation.
60+
allowUnfinalizedQueries bool
6061
eth *Ethereum
6162
gpo *gasprice.Oracle
6263
}
@@ -66,8 +67,12 @@ func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
6667
return b.eth.blockchain.Config()
6768
}
6869

69-
func (b *EthAPIBackend) GetVMConfig() *vm.Config {
70-
return b.eth.blockchain.GetVMConfig()
70+
func (b *EthAPIBackend) IsAllowUnfinalizedQueries() bool {
71+
return b.allowUnfinalizedQueries
72+
}
73+
74+
func (b *EthAPIBackend) SetAllowUnfinalizedQueries(allow bool) {
75+
b.allowUnfinalizedQueries = allow
7176
}
7277

7378
func (b *EthAPIBackend) CurrentBlock() *types.Header {
@@ -89,7 +94,7 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
8994
return acceptedBlock.Header(), nil
9095
}
9196

92-
if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil {
97+
if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil {
9398
if number.Int64() > acceptedBlock.Number().Int64() {
9499
return nil, ErrUnfinalizedData
95100
}
@@ -113,7 +118,7 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty
113118
}
114119

115120
acceptedBlock := b.eth.LastAcceptedBlock()
116-
if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil {
121+
if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil {
117122
if header.Number.Cmp(acceptedBlock.Number()) > 0 {
118123
return nil, ErrUnfinalizedData
119124
}
@@ -149,7 +154,7 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
149154
return acceptedBlock, nil
150155
}
151156

152-
if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil {
157+
if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil {
153158
if number.Int64() > acceptedBlock.Number().Int64() {
154159
return nil, ErrUnfinalizedData
155160
}
@@ -174,7 +179,7 @@ func (b *EthAPIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*typ
174179
}
175180

176181
acceptedBlock := b.eth.LastAcceptedBlock()
177-
if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil {
182+
if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil {
178183
if number.Cmp(acceptedBlock.Number()) > 0 {
179184
return nil, ErrUnfinalizedData
180185
}
@@ -345,7 +350,7 @@ func (b *EthAPIBackend) GetTransaction(ctx context.Context, txHash common.Hash)
345350
// expectations with clients (expect an empty response when a transaction
346351
// does not exist).
347352
acceptedBlock := b.eth.LastAcceptedBlock()
348-
if !b.GetVMConfig().AllowUnfinalizedQueries && acceptedBlock != nil && tx != nil {
353+
if !b.IsAllowUnfinalizedQueries() && acceptedBlock != nil && tx != nil {
349354
if blockNumber > acceptedBlock.NumberU64() {
350355
return nil, common.Hash{}, 0, 0, nil
351356
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func New(
182182
var (
183183
vmConfig = vm.Config{
184184
EnablePreimageRecording: config.EnablePreimageRecording,
185-
AllowUnfinalizedQueries: config.AllowUnfinalizedQueries,
186185
}
187186
cacheConfig = &core.CacheConfig{
188187
TrieCleanLimit: config.TrieCleanCache,
@@ -239,6 +238,7 @@ func New(
239238
extRPCEnabled: stack.Config().ExtRPCEnabled(),
240239
allowUnprotectedTxs: config.AllowUnprotectedTxs,
241240
allowUnprotectedTxHashes: allowUnprotectedTxHashes,
241+
allowUnfinalizedQueries: config.AllowUnfinalizedQueries,
242242
eth: eth,
243243
}
244244
if config.AllowUnprotectedTxs {

eth/filters/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (api *FilterAPI) NewBlockFilter() rpc.ID {
245245
headerSub *Subscription
246246
)
247247

248-
if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries {
248+
if api.sys.backend.IsAllowUnfinalizedQueries() {
249249
headerSub = api.events.SubscribeNewHeads(headers)
250250
} else {
251251
headerSub = api.events.SubscribeAcceptedHeads(headers)
@@ -291,7 +291,7 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) {
291291
headersSub event.Subscription
292292
)
293293

294-
if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries {
294+
if api.sys.backend.IsAllowUnfinalizedQueries() {
295295
headersSub = api.events.SubscribeNewHeads(headers)
296296
} else {
297297
headersSub = api.events.SubscribeAcceptedHeads(headers)
@@ -328,7 +328,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
328328
err error
329329
)
330330

331-
if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries {
331+
if api.sys.backend.IsAllowUnfinalizedQueries() {
332332
logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), matchedLogs)
333333
if err != nil {
334334
return nil, err
@@ -383,7 +383,7 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
383383
err error
384384
)
385385

386-
if api.sys.backend.GetVMConfig().AllowUnfinalizedQueries {
386+
if api.sys.backend.IsAllowUnfinalizedQueries() {
387387
logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), logs)
388388
if err != nil {
389389
return rpc.ID(""), err

eth/filters/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Filter struct {
5454
// NewRangeFilter creates a new filter which uses a bloom filter on blocks to
5555
// figure out whether a particular block is interesting or not.
5656
func (sys *FilterSystem) NewRangeFilter(begin, end int64, addresses []common.Address, topics [][]common.Hash) (*Filter, error) {
57-
allowUnfinalizedQueries := sys.backend.GetVMConfig().AllowUnfinalizedQueries
57+
allowUnfinalizedQueries := sys.backend.IsAllowUnfinalizedQueries()
5858
acceptedBlock := sys.backend.LastAcceptedBlock()
5959

6060
// Flatten the address and topic filter clauses into a single bloombits filter

eth/filters/filter_system.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/ava-labs/coreth/core"
3939
"github.com/ava-labs/coreth/core/bloombits"
4040
"github.com/ava-labs/coreth/core/types"
41-
"github.com/ava-labs/coreth/core/vm"
4241
"github.com/ava-labs/coreth/ethdb"
4342
"github.com/ava-labs/coreth/interfaces"
4443
"github.com/ava-labs/coreth/params"
@@ -85,7 +84,7 @@ type Backend interface {
8584
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
8685

8786
// Added to the backend interface to support limiting of logs requests
88-
GetVMConfig() *vm.Config
87+
IsAllowUnfinalizedQueries() bool
8988
LastAcceptedBlock() *types.Block
9089
GetMaxBlocksPerRequest() int64
9190
}

eth/filters/filter_system_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"github.com/ava-labs/coreth/core/bloombits"
4343
"github.com/ava-labs/coreth/core/rawdb"
4444
"github.com/ava-labs/coreth/core/types"
45-
"github.com/ava-labs/coreth/core/vm"
4645
"github.com/ava-labs/coreth/ethdb"
4746
"github.com/ava-labs/coreth/interfaces"
4847
"github.com/ava-labs/coreth/internal/ethapi"
@@ -78,8 +77,8 @@ func (b *testBackend) ChainDb() ethdb.Database {
7877
return b.db
7978
}
8079

81-
func (b *testBackend) GetVMConfig() *vm.Config {
82-
return &vm.Config{AllowUnfinalizedQueries: true}
80+
func (b *testBackend) IsAllowUnfinalizedQueries() bool {
81+
return true
8382
}
8483

8584
func (b *testBackend) GetMaxBlocksPerRequest() int64 {

plugin/evm/vm_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ func TestNonCanonicalAccept(t *testing.T) {
21092109
t.Fatal(err)
21102110
}
21112111

2112-
vm1.blockChain.GetVMConfig().AllowUnfinalizedQueries = true
2112+
vm1.eth.APIBackend.SetAllowUnfinalizedQueries(true)
21132113

21142114
blkBHeight := vm1BlkB.Height()
21152115
blkBHash := vm1BlkB.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash()
@@ -2284,7 +2284,7 @@ func TestStickyPreference(t *testing.T) {
22842284
t.Fatal(err)
22852285
}
22862286

2287-
vm1.blockChain.GetVMConfig().AllowUnfinalizedQueries = true
2287+
vm1.eth.APIBackend.SetAllowUnfinalizedQueries(true)
22882288

22892289
blkBHeight := vm1BlkB.Height()
22902290
blkBHash := vm1BlkB.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash()
@@ -3129,7 +3129,7 @@ func TestLastAcceptedBlockNumberAllow(t *testing.T) {
31293129
blkHeight := blk.Height()
31303130
blkHash := blk.(*chain.BlockWrapper).Block.(*Block).ethBlock.Hash()
31313131

3132-
vm.blockChain.GetVMConfig().AllowUnfinalizedQueries = true
3132+
vm.eth.APIBackend.SetAllowUnfinalizedQueries(true)
31333133

31343134
ctx := context.Background()
31353135
b, err := vm.eth.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(blkHeight))
@@ -3140,7 +3140,7 @@ func TestLastAcceptedBlockNumberAllow(t *testing.T) {
31403140
t.Fatalf("expected block at %d to have hash %s but got %s", blkHeight, blkHash.Hex(), b.Hash().Hex())
31413141
}
31423142

3143-
vm.blockChain.GetVMConfig().AllowUnfinalizedQueries = false
3143+
vm.eth.APIBackend.SetAllowUnfinalizedQueries(false)
31443144

31453145
_, err = vm.eth.APIBackend.BlockByNumber(ctx, rpc.BlockNumber(blkHeight))
31463146
if !errors.Is(err, eth.ErrUnfinalizedData) {

0 commit comments

Comments
 (0)