Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
28be4fa2
Unverified
Commit
28be4fa2
authored
Aug 29, 2023
by
OptimismBot
Committed by
GitHub
Aug 29, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7057 from ethereum-optimism/aj/l2-transactions
op-program: Support prefetching l2-transactions
parents
73f2c2b3
c6d0829c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
oracle.go
op-program/client/l2/oracle.go
+8
-3
prefetcher.go
op-program/host/prefetcher/prefetcher.go
+1
-1
prefetcher_test.go
op-program/host/prefetcher/prefetcher_test.go
+25
-0
No files found.
op-program/client/l2/oracle.go
View file @
28be4fa2
...
@@ -64,9 +64,15 @@ func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash) *types.Header
...
@@ -64,9 +64,15 @@ func (p *PreimageOracle) headerByBlockHash(blockHash common.Hash) *types.Header
func
(
p
*
PreimageOracle
)
BlockByHash
(
blockHash
common
.
Hash
)
*
types
.
Block
{
func
(
p
*
PreimageOracle
)
BlockByHash
(
blockHash
common
.
Hash
)
*
types
.
Block
{
header
:=
p
.
headerByBlockHash
(
blockHash
)
header
:=
p
.
headerByBlockHash
(
blockHash
)
txs
:=
p
.
LoadTransactions
(
blockHash
,
header
.
TxHash
)
return
types
.
NewBlockWithHeader
(
header
)
.
WithBody
(
txs
,
nil
)
}
func
(
p
*
PreimageOracle
)
LoadTransactions
(
blockHash
common
.
Hash
,
txHash
common
.
Hash
)
[]
*
types
.
Transaction
{
p
.
hint
.
Hint
(
TransactionsHint
(
blockHash
))
p
.
hint
.
Hint
(
TransactionsHint
(
blockHash
))
opaqueTxs
:=
mpt
.
ReadTrie
(
header
.
T
xHash
,
func
(
key
common
.
Hash
)
[]
byte
{
opaqueTxs
:=
mpt
.
ReadTrie
(
t
xHash
,
func
(
key
common
.
Hash
)
[]
byte
{
return
p
.
oracle
.
Get
(
preimage
.
Keccak256Key
(
key
))
return
p
.
oracle
.
Get
(
preimage
.
Keccak256Key
(
key
))
})
})
...
@@ -74,8 +80,7 @@ func (p *PreimageOracle) BlockByHash(blockHash common.Hash) *types.Block {
...
@@ -74,8 +80,7 @@ func (p *PreimageOracle) BlockByHash(blockHash common.Hash) *types.Block {
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"failed to decode list of txs: %w"
,
err
))
panic
(
fmt
.
Errorf
(
"failed to decode list of txs: %w"
,
err
))
}
}
return
txs
return
types
.
NewBlockWithHeader
(
header
)
.
WithBody
(
txs
,
nil
)
}
}
func
(
p
*
PreimageOracle
)
NodeByHash
(
nodeHash
common
.
Hash
)
[]
byte
{
func
(
p
*
PreimageOracle
)
NodeByHash
(
nodeHash
common
.
Hash
)
[]
byte
{
...
...
op-program/host/prefetcher/prefetcher.go
View file @
28be4fa2
...
@@ -99,7 +99,7 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error {
...
@@ -99,7 +99,7 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error {
return
fmt
.
Errorf
(
"failed to fetch L1 block %s receipts: %w"
,
hash
,
err
)
return
fmt
.
Errorf
(
"failed to fetch L1 block %s receipts: %w"
,
hash
,
err
)
}
}
return
p
.
storeReceipts
(
receipts
)
return
p
.
storeReceipts
(
receipts
)
case
l2
.
HintL2BlockHeader
:
case
l2
.
HintL2BlockHeader
,
l2
.
HintL2Transactions
:
header
,
txs
,
err
:=
p
.
l2Fetcher
.
InfoAndTxsByHash
(
ctx
,
hash
)
header
,
txs
,
err
:=
p
.
l2Fetcher
.
InfoAndTxsByHash
(
ctx
,
hash
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to fetch L2 block %s: %w"
,
hash
,
err
)
return
fmt
.
Errorf
(
"failed to fetch L2 block %s: %w"
,
hash
,
err
)
...
...
op-program/host/prefetcher/prefetcher_test.go
View file @
28be4fa2
...
@@ -180,6 +180,31 @@ func TestFetchL2Block(t *testing.T) {
...
@@ -180,6 +180,31 @@ func TestFetchL2Block(t *testing.T) {
})
})
}
}
func
TestFetchL2Transactions
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
123
))
block
,
rcpts
:=
testutils
.
RandomBlock
(
rng
,
10
)
hash
:=
block
.
Hash
()
t
.
Run
(
"AlreadyKnown"
,
func
(
t
*
testing
.
T
)
{
prefetcher
,
_
,
_
,
kv
:=
createPrefetcher
(
t
)
storeBlock
(
t
,
kv
,
block
,
rcpts
)
oracle
:=
l2
.
NewPreimageOracle
(
asOracleFn
(
t
,
prefetcher
),
asHinter
(
t
,
prefetcher
))
result
:=
oracle
.
LoadTransactions
(
hash
,
block
.
TxHash
())
assertTransactionsEqual
(
t
,
block
.
Transactions
(),
result
)
})
t
.
Run
(
"Unknown"
,
func
(
t
*
testing
.
T
)
{
prefetcher
,
_
,
l2Cl
,
_
:=
createPrefetcher
(
t
)
l2Cl
.
ExpectInfoAndTxsByHash
(
hash
,
eth
.
BlockToInfo
(
block
),
block
.
Transactions
(),
nil
)
defer
l2Cl
.
MockL2Client
.
AssertExpectations
(
t
)
oracle
:=
l2
.
NewPreimageOracle
(
asOracleFn
(
t
,
prefetcher
),
asHinter
(
t
,
prefetcher
))
result
:=
oracle
.
LoadTransactions
(
hash
,
block
.
TxHash
())
assertTransactionsEqual
(
t
,
block
.
Transactions
(),
result
)
})
}
func
TestFetchL2Node
(
t
*
testing
.
T
)
{
func
TestFetchL2Node
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
123
))
rng
:=
rand
.
New
(
rand
.
NewSource
(
123
))
node
:=
testutils
.
RandomData
(
rng
,
30
)
node
:=
testutils
.
RandomData
(
rng
,
30
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment