Skip to content

Commit 633936f

Browse files
committed
Implement SendExpressLaneTransactionSync
1 parent d5da929 commit 633936f

File tree

8 files changed

+47
-26
lines changed

8 files changed

+47
-26
lines changed

arbitrum/apibackend.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ type SyncProgressBackend interface {
132132
BlockMetadataByNumber(ctx context.Context, blockNum uint64) (common.BlockMetadata, error)
133133
}
134134

135-
func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fallbackClientUrl string, fallbackClientTimeout time.Duration, archiveRedirects []BlockRedirectConfig) (*filters.FilterSystem, error) {
135+
func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fallbackClientUrl string, fallbackClientTimeout time.Duration, archiveRedirects []BlockRedirectConfig) (*filters.FilterSystem, ReceiptFetcher, error) {
136136
fallbackClient, err := CreateFallbackClient(fallbackClientUrl, fallbackClientTimeout, false)
137137
if err != nil {
138-
return nil, err
138+
return nil, nil, err
139139
}
140140
var archiveClientsManager *archiveFallbackClientsManager
141141
if len(archiveRedirects) != 0 {
142142
archiveClientsManager, err = newArchiveFallbackClientsManager(archiveRedirects)
143143
if err != nil {
144-
return nil, err
144+
return nil, nil, err
145145
}
146146
}
147147
backend.apiBackend = &APIBackend{
@@ -150,8 +150,9 @@ func createRegisterAPIBackend(backend *Backend, filterConfig filters.Config, fal
150150
archiveClientsManager: archiveClientsManager,
151151
}
152152
filterSystem := filters.NewFilterSystem(backend.apiBackend, filterConfig)
153-
backend.stack.RegisterAPIs(backend.apiBackend.GetAPIs(filterSystem))
154-
return filterSystem, nil
153+
apis, receiptFetcher := backend.apiBackend.GetAPIs(filterSystem)
154+
backend.stack.RegisterAPIs(apis)
155+
return filterSystem, receiptFetcher, nil
155156
}
156157

157158
func (a *APIBackend) SetSyncBackend(sync SyncProgressBackend) error {
@@ -162,8 +163,8 @@ func (a *APIBackend) SetSyncBackend(sync SyncProgressBackend) error {
162163
return nil
163164
}
164165

165-
func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) []rpc.API {
166-
apis := ethapi.GetAPIs(a)
166+
func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) ([]rpc.API, ReceiptFetcher) {
167+
apis, transactionAPI := ethapi.GetAPIs(a)
167168

168169
apis = append(apis, rpc.API{
169170
Namespace: "eth",
@@ -195,7 +196,7 @@ func (a *APIBackend) GetAPIs(filterSystem *filters.FilterSystem) []rpc.API {
195196

196197
apis = append(apis, tracers.APIs(a)...)
197198

198-
return apis
199+
return apis, transactionAPI
199200
}
200201

201202
func (a *APIBackend) BlockChain() *core.BlockChain {

arbitrum/backend.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/ethereum/go-ethereum/internal/shutdowncheck"
1818
"github.com/ethereum/go-ethereum/log"
1919
"github.com/ethereum/go-ethereum/node"
20-
"github.com/ethereum/go-ethereum/rpc"
2120
)
2221

2322
type Backend struct {
@@ -30,7 +29,8 @@ type Backend struct {
3029
txFeed event.Feed
3130
scope event.SubscriptionScope
3231

33-
filterMaps *filtermaps.FilterMaps
32+
filterMaps *filtermaps.FilterMaps
33+
receiptFetcher ReceiptFetcher
3434

3535
shutdownTracker *shutdowncheck.ShutdownTracker
3636

@@ -84,13 +84,15 @@ func NewBackend(stack *node.Node, config *Config, chainDb ethdb.Database, publis
8484
backend.stack.ApplyAPIFilter(rpcFilter)
8585
}
8686

87-
filterSystem, err := createRegisterAPIBackend(backend, filterConfig, config.ClassicRedirect, config.ClassicRedirectTimeout, config.BlockRedirects)
87+
filterSystem, receiptFetcher, err := createRegisterAPIBackend(backend, filterConfig, config.ClassicRedirect, config.ClassicRedirectTimeout, config.BlockRedirects)
8888
if err != nil {
8989
return nil, nil, err
9090
}
9191
backend.filterSystem = filterSystem
92+
backend.receiptFetcher = receiptFetcher
9293
return backend, filterSystem, nil
9394
}
95+
9496
func (b *Backend) newChainView(head *types.Header) *filtermaps.ChainView {
9597
if head == nil {
9698
return nil
@@ -100,11 +102,12 @@ func (b *Backend) newChainView(head *types.Header) *filtermaps.ChainView {
100102

101103
func (b *Backend) AccountManager() *accounts.Manager { return b.stack.AccountManager() }
102104
func (b *Backend) APIBackend() *APIBackend { return b.apiBackend }
103-
func (b *Backend) APIs() []rpc.API { return b.apiBackend.GetAPIs(b.filterSystem) }
104105
func (b *Backend) ArbInterface() ArbInterface { return b.arb }
105106
func (b *Backend) BlockChain() *core.BlockChain { return b.arb.BlockChain() }
106107
func (b *Backend) ChainDb() ethdb.Database { return b.chainDb }
108+
func (b *Backend) Config() *Config { return b.config }
107109
func (b *Backend) Engine() consensus.Engine { return b.arb.BlockChain().Engine() }
110+
func (b *Backend) ReceiptFetcher() ReceiptFetcher { return b.receiptFetcher }
108111
func (b *Backend) Stack() *node.Node { return b.stack }
109112

110113
func (b *Backend) ResetWithGenesisBlock(gb *types.Block) {

arbitrum/receipt.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package arbitrum
2+
3+
import (
4+
"context"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/ethereum/go-ethereum/core/types"
8+
"github.com/ethereum/go-ethereum/internal/ethapi"
9+
"github.com/ethereum/go-ethereum/params"
10+
)
11+
12+
type ReceiptFetcher interface {
13+
GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)
14+
}
15+
16+
// Exposing the internal function, this should make maintaining the upstream code easier
17+
func MarshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex uint64, chainConfig *params.ChainConfig, header *types.Header, blockMetadata common.BlockMetadata) map[string]interface{} {
18+
return ethapi.MarshalReceipt(receipt, blockHash, blockNumber, signer, tx, txIndex, chainConfig, header, blockMetadata)
19+
}

common/types.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,11 @@ type BlockMetadata []byte
495495
// 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
496496
// blockMetadata[index / 8 + 1] & (1 << (index % 8)) != 0; where index = (N - 1), implies whether (N)th tx in a block is timeboosted
497497
// 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
498-
func (b BlockMetadata) IsTxTimeboosted(txIndex int) (bool, error) {
498+
func (b BlockMetadata) IsTxTimeboosted(txIndex uint64) (bool, error) {
499499
if len(b) == 0 {
500500
return false, errors.New("blockMetadata is not set")
501501
}
502-
if txIndex < 0 {
503-
return false, fmt.Errorf("invalid transaction index- %d, should be positive", txIndex)
504-
}
505-
maxTxCount := (len(b) - 1) * 8
502+
maxTxCount := (uint64(len(b)) - 1) * 8
506503
if txIndex >= maxTxCount {
507504
return false, nil
508505
}

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func makeExtraData(extra []byte) []byte {
394394
// APIs return the collection of RPC services the ethereum package offers.
395395
// NOTE, some of these services probably need to be moved to somewhere else.
396396
func (s *Ethereum) APIs() []rpc.API {
397-
apis := ethapi.GetAPIs(s.APIBackend)
397+
apis, _ := ethapi.GetAPIs(s.APIBackend)
398398

399399
// Append all the local APIs and return
400400
return append(apis, []rpc.API{

eth/filters/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func (api *FilterAPI) TransactionReceipts(ctx context.Context, filter *Transacti
370370
receiptWithTx.Receipt.BlockNumber.Uint64(),
371371
signer,
372372
receiptWithTx.Transaction,
373-
int(receiptWithTx.Receipt.TransactionIndex),
373+
uint64(receiptWithTx.Receipt.TransactionIndex),
374374
api.events.backend.ChainConfig(),
375375
header,
376376
blockMetadata,

internal/ethapi/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp
657657
if err != nil {
658658
return nil, err
659659
}
660-
result[i] = MarshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, api.b.ChainConfig(), header, blockMetadata)
660+
result[i] = MarshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], uint64(i), api.b.ChainConfig(), header, blockMetadata)
661661
}
662662
return result, nil
663663
}
@@ -1758,11 +1758,11 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo
17581758
if err != nil {
17591759
return nil, err
17601760
}
1761-
return MarshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index), api.b.ChainConfig(), header, blockMetadata), nil
1761+
return MarshalReceipt(receipt, blockHash, blockNumber, signer, tx, index, api.b.ChainConfig(), header, blockMetadata), nil
17621762
}
17631763

17641764
// MarshalReceipt marshals a transaction receipt into a JSON object.
1765-
func MarshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, chainConfig *params.ChainConfig, header *types.Header, blockMetadata common.BlockMetadata) map[string]interface{} {
1765+
func MarshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex uint64, chainConfig *params.ChainConfig, header *types.Header, blockMetadata common.BlockMetadata) map[string]interface{} {
17661766
from, _ := types.Sender(signer, tx)
17671767

17681768
fields := map[string]interface{}{
@@ -2062,7 +2062,7 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex
20622062
rs[i].BlockNumber.Uint64(),
20632063
signer,
20642064
txs[i],
2065-
int(rs[i].TransactionIndex),
2065+
uint64(rs[i].TransactionIndex),
20662066
api.b.ChainConfig(),
20672067
header,
20682068
blockMetadata,

internal/ethapi/backend.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ type Backend interface {
108108
NewMatcherBackend() filtermaps.MatcherBackend
109109
}
110110

111-
func GetAPIs(apiBackend Backend) []rpc.API {
111+
func GetAPIs(apiBackend Backend) ([]rpc.API, *TransactionAPI) {
112112
nonceLock := new(AddrLocker)
113+
transactionAPI := NewTransactionAPI(apiBackend, nonceLock)
113114
return []rpc.API{
114115
{
115116
Namespace: "eth",
@@ -119,7 +120,7 @@ func GetAPIs(apiBackend Backend) []rpc.API {
119120
Service: NewBlockChainAPI(apiBackend),
120121
}, {
121122
Namespace: "eth",
122-
Service: NewTransactionAPI(apiBackend, nonceLock),
123+
Service: transactionAPI,
123124
}, {
124125
Namespace: "txpool",
125126
Service: NewTxPoolAPI(apiBackend),
@@ -130,5 +131,5 @@ func GetAPIs(apiBackend Backend) []rpc.API {
130131
Namespace: "eth",
131132
Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
132133
},
133-
}
134+
}, transactionAPI
134135
}

0 commit comments

Comments
 (0)