Skip to content

Commit 8457713

Browse files
committed
Merge branch 'master' into export-rawdb-funcs
2 parents fe38b30 + 8070936 commit 8457713

File tree

8 files changed

+49
-1
lines changed

8 files changed

+49
-1
lines changed

arbitrum/apibackend.go

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type SyncProgressBackend interface {
9696
SyncProgressMap() map[string]interface{}
9797
SafeBlockNumber(ctx context.Context) (uint64, error)
9898
FinalizedBlockNumber(ctx context.Context) (uint64, error)
99+
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error)
99100
}
100101

101102
func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fallbackClientUrl string, fallbackClientTimeout time.Duration) (*filters.FilterSystem, error) {
@@ -460,6 +461,10 @@ func (a *APIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
460461
return nil, errors.New("invalid arguments; neither block nor hash specified")
461462
}
462463

464+
func (a *APIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
465+
return a.sync.BlockMetadataByNumber(blockNum)
466+
}
467+
463468
func StateAndHeaderFromHeader(ctx context.Context, chainDb ethdb.Database, bc *core.BlockChain, maxRecreateStateDepth int64, header *types.Header, err error) (*state.StateDB, *types.Header, error) {
464469
if err != nil {
465470
return nil, header, err

common/types.go

+21
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,24 @@ func (b PrettyBytes) TerminalString() string {
486486
}
487487
return fmt.Sprintf("%#x...%x (%dB)", b[:3], b[len(b)-3:], len(b))
488488
}
489+
490+
type BlockMetadata []byte
491+
492+
// IsTxTimeboosted given a tx's index in the block returns whether the tx was timeboosted
493+
// or not. The first byte of blockMetadata byte array is reserved to indicate the version,
494+
// starting from the second byte, (N)th bit would represent if (N)th tx is timeboosted or not, 1 means yes and 0 means no
495+
// blockMetadata[index / 8 + 1] & (1 << (index % 8)) != 0; where index = (N - 1), implies whether (N)th tx in a block is timeboosted
496+
// note that number of txs in a block will always lag behind (len(blockMetadata) - 1) * 8 but it wont lag more than a value of 7
497+
func (b BlockMetadata) IsTxTimeboosted(txIndex int) (bool, error) {
498+
if len(b) == 0 {
499+
return false, errors.New("blockMetadata is not set")
500+
}
501+
if txIndex < 0 {
502+
return false, fmt.Errorf("invalid transaction index- %d, should be positive", txIndex)
503+
}
504+
maxTxCount := (len(b) - 1) * 8
505+
if txIndex >= maxTxCount {
506+
return false, nil
507+
}
508+
return b[1+(txIndex/8)]&(1<<(txIndex%8)) != 0, nil
509+
}

eth/api_backend.go

+4
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
182182
return nil, errors.New("invalid arguments; neither block nor hash specified")
183183
}
184184

185+
func (b *EthAPIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
186+
return nil, nil
187+
}
188+
185189
func (b *EthAPIBackend) Pending() (*types.Block, types.Receipts, *state.StateDB) {
186190
return b.eth.miner.Pending()
187191
}

eth/tracers/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ func newTestMergedBackend(t *testing.T, n int, gspec *core.Genesis, generator fu
10191019
SnapshotLimit: 0,
10201020
TrieDirtyDisabled: true, // Archive mode
10211021
}
1022-
chain, err := core.NewBlockChain(backend.chaindb, cacheConfig, gspec, nil, backend.engine, vm.Config{}, nil, nil)
1022+
chain, err := core.NewBlockChain(backend.chaindb, cacheConfig, nil, gspec, nil, backend.engine, vm.Config{}, nil, nil)
10231023
if err != nil {
10241024
t.Fatalf("failed to create tester chain: %v", err)
10251025
}

internal/ethapi/api.go

+11
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,17 @@ func marshalReceipt(ctx context.Context, receipt *types.Receipt, blockHash commo
19831983
fields["l1BlockNumber"] = hexutil.Uint64(arbTx.L1BlockNumber)
19841984
}
19851985
}
1986+
1987+
blockMetadata, err := backend.BlockMetadataByNumber(blockNumber)
1988+
if err != nil {
1989+
return nil, err
1990+
}
1991+
if blockMetadata != nil {
1992+
fields["timeboosted"], err = blockMetadata.IsTxTimeboosted(txIndex)
1993+
if err != nil {
1994+
log.Error("Error checking if a tx was timeboosted", "txIndex", txIndex, "txHash", tx.Hash(), "err", err)
1995+
}
1996+
}
19861997
}
19871998
return fields, nil
19881999
}

internal/ethapi/api_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ func (b testBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
527527
}
528528
panic("unknown type rpc.BlockNumberOrHash")
529529
}
530+
func (b testBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
531+
return nil, nil
532+
}
530533
func (b testBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
531534
return b.chain.GetBlock(hash, uint64(number.Int64())).Body(), nil
532535
}

internal/ethapi/backend.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type Backend interface {
6767
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
6868
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
6969
BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
70+
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error)
7071
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
7172
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
7273
Pending() (*types.Block, types.Receipts, *state.StateDB)

internal/ethapi/transaction_args_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ func (b *backendMock) BlockByHash(ctx context.Context, hash common.Hash) (*types
351351
func (b *backendMock) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) {
352352
return nil, nil
353353
}
354+
func (b *backendMock) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
355+
return nil, nil
356+
}
354357
func (b *backendMock) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
355358
return nil, nil
356359
}

0 commit comments

Comments
 (0)