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

Add a boolean field to tx receipt object indicating if the tx was timeboosted #369

Open
wants to merge 3 commits into
base: add-methodsto-sizeconstrainedcache
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type SyncProgressBackend interface {
SyncProgressMap() map[string]interface{}
SafeBlockNumber(ctx context.Context) (uint64, error)
FinalizedBlockNumber(ctx context.Context) (uint64, error)
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error)
}

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

func (a *APIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
return a.sync.BlockMetadataByNumber(blockNum)
}

func StateAndHeaderFromHeader(ctx context.Context, chainDb ethdb.Database, bc *core.BlockChain, maxRecreateStateDepth int64, header *types.Header, err error) (*state.StateDB, *types.Header, error) {
if err != nil {
return nil, header, err
Expand Down
11 changes: 11 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,14 @@ func (d *Decimal) UnmarshalJSON(input []byte) error {
return err
}
}

type BlockMetadata []byte

// IsTxTimeboosted given a tx's index in the block returns whether the tx was timeboosted or not
func (b BlockMetadata) IsTxTimeboosted(txIndex int) bool {
maxTxCount := (len(b) - 1) * 8
if txIndex >= maxTxCount {
return false
}
return b[1+(txIndex/8)]&(1<<(txIndex%8)) != 0
}
4 changes: 4 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
return nil, errors.New("invalid arguments; neither block nor hash specified")
}

func (b *EthAPIBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}

func (b *EthAPIBackend) PendingBlockAndReceipts() (*types.Block, types.Receipts) {
return b.eth.miner.PendingBlockAndReceipts()
}
Expand Down
8 changes: 8 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,14 @@ func marshalReceipt(ctx context.Context, receipt *types.Receipt, blockHash commo
fields["l1BlockNumber"] = hexutil.Uint64(arbTx.L1BlockNumber)
}
}

blockMetadata, err := backend.BlockMetadataByNumber(blockNumber)
if err != nil {
return nil, err
}
if blockMetadata != nil {
fields["timeboosted"] = blockMetadata.IsTxTimeboosted(txIndex)
}
}
return fields, nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ func (b testBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
}
panic("unknown type rpc.BlockNumberOrHash")
}
func (b testBackend) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}
func (b testBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
return b.chain.GetBlock(hash, uint64(number.Int64())).Body(), nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Backend interface {
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error)
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
PendingBlockAndReceipts() (*types.Block, types.Receipts)
Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ func (b *backendMock) BlockByHash(ctx context.Context, hash common.Hash) (*types
func (b *backendMock) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) {
return nil, nil
}
func (b *backendMock) BlockMetadataByNumber(blockNum uint64) (common.BlockMetadata, error) {
return nil, nil
}
func (b *backendMock) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
return nil, nil
}
Expand Down
Loading