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
a13ff5f8
Unverified
Commit
a13ff5f8
authored
Apr 17, 2023
by
OptimismBot
Committed by
GitHub
Apr 17, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5463 from ethereum-optimism/aj/block-info-rlp
Add a HeaderRLP method to BlockInfo
parents
e15d068f
98dced7a
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
94 additions
and
86 deletions
+94
-86
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+2
-2
op_geth.go
op-e2e/op_geth.go
+1
-1
block_info.go
op-node/eth/block_info.go
+22
-2
random.go
op-node/rollup/derive/test/random.go
+1
-1
eth_client.go
op-node/sources/eth_client.go
+4
-4
types.go
op-node/sources/types.go
+38
-60
l1info.go
op-node/testutils/l1info.go
+9
-0
cache_test.go
op-program/client/l1/cache_test.go
+7
-6
client_test.go
op-program/client/l1/client_test.go
+4
-5
fetcher_test.go
op-program/host/l1/fetcher_test.go
+6
-5
No files found.
op-batcher/batcher/channel_builder_test.go
View file @
a13ff5f8
...
@@ -137,7 +137,7 @@ func newMiniL2BlockWithNumberParent(numTx int, number *big.Int, parent common.Ha
...
@@ -137,7 +137,7 @@ func newMiniL2BlockWithNumberParent(numTx int, number *big.Int, parent common.Ha
Difficulty
:
common
.
Big0
,
Difficulty
:
common
.
Big0
,
Number
:
big
.
NewInt
(
100
),
Number
:
big
.
NewInt
(
100
),
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
l1Block
,
eth
.
SystemConfig
{},
false
)
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
eth
.
BlockToInfo
(
l1Block
)
,
eth
.
SystemConfig
{},
false
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
...
@@ -517,7 +517,7 @@ func TestChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T) {
...
@@ -517,7 +517,7 @@ func TestChannelBuilder_OutputFramesMaxFrameIndex(t *testing.T) {
Difficulty
:
common
.
Big0
,
Difficulty
:
common
.
Big0
,
Number
:
common
.
Big0
,
Number
:
common
.
Big0
,
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
_
:=
derive
.
L1InfoDeposit
(
0
,
lBlock
,
eth
.
SystemConfig
{},
false
)
l1InfoTx
,
_
:=
derive
.
L1InfoDeposit
(
0
,
eth
.
BlockToInfo
(
lBlock
)
,
eth
.
SystemConfig
{},
false
)
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
a
:=
types
.
NewBlock
(
&
types
.
Header
{
a
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
0
),
Number
:
big
.
NewInt
(
0
),
...
...
op-e2e/op_geth.go
View file @
a13ff5f8
...
@@ -100,7 +100,7 @@ func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, e
...
@@ -100,7 +100,7 @@ func NewOpGeth(t *testing.T, ctx context.Context, cfg *SystemConfig) (*OpGeth, e
SystemConfig
:
rollupGenesis
.
SystemConfig
,
SystemConfig
:
rollupGenesis
.
SystemConfig
,
L1ChainConfig
:
l1Genesis
.
Config
,
L1ChainConfig
:
l1Genesis
.
Config
,
L2ChainConfig
:
l2Genesis
.
Config
,
L2ChainConfig
:
l2Genesis
.
Config
,
L1Head
:
l1Block
,
L1Head
:
eth
.
BlockToInfo
(
l1Block
)
,
L2Head
:
genesisPayload
,
L2Head
:
genesisPayload
,
},
nil
},
nil
}
}
...
...
op-node/eth/block_info.go
View file @
a13ff5f8
...
@@ -5,10 +5,9 @@ import (
...
@@ -5,10 +5,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
)
)
var
_
BlockInfo
=
(
&
types
.
Block
{})
type
BlockInfo
interface
{
type
BlockInfo
interface
{
Hash
()
common
.
Hash
Hash
()
common
.
Hash
ParentHash
()
common
.
Hash
ParentHash
()
common
.
Hash
...
@@ -21,6 +20,10 @@ type BlockInfo interface {
...
@@ -21,6 +20,10 @@ type BlockInfo interface {
BaseFee
()
*
big
.
Int
BaseFee
()
*
big
.
Int
ReceiptHash
()
common
.
Hash
ReceiptHash
()
common
.
Hash
GasUsed
()
uint64
GasUsed
()
uint64
// HeaderRLP returns the RLP of the block header as per consensus rules
// Returns an error if the header RLP could not be written
HeaderRLP
()
([]
byte
,
error
)
}
}
func
InfoToL1BlockRef
(
info
BlockInfo
)
L1BlockRef
{
func
InfoToL1BlockRef
(
info
BlockInfo
)
L1BlockRef
{
...
@@ -44,6 +47,19 @@ func ToBlockID(b NumberAndHash) BlockID {
...
@@ -44,6 +47,19 @@ func ToBlockID(b NumberAndHash) BlockID {
}
}
}
}
// blockInfo is a conversion type of types.Block turning it into a BlockInfo
type
blockInfo
struct
{
*
types
.
Block
}
func
(
b
blockInfo
)
HeaderRLP
()
([]
byte
,
error
)
{
return
rlp
.
EncodeToBytes
(
b
.
Header
())
}
func
BlockToInfo
(
b
*
types
.
Block
)
BlockInfo
{
return
blockInfo
{
b
}
}
var
_
BlockInfo
=
(
*
blockInfo
)(
nil
)
// headerBlockInfo is a conversion type of types.Header turning it into a
// headerBlockInfo is a conversion type of types.Header turning it into a
// BlockInfo.
// BlockInfo.
type
headerBlockInfo
struct
{
*
types
.
Header
}
type
headerBlockInfo
struct
{
*
types
.
Header
}
...
@@ -84,6 +100,10 @@ func (h headerBlockInfo) GasUsed() uint64 {
...
@@ -84,6 +100,10 @@ func (h headerBlockInfo) GasUsed() uint64 {
return
h
.
Header
.
GasUsed
return
h
.
Header
.
GasUsed
}
}
func
(
h
headerBlockInfo
)
HeaderRLP
()
([]
byte
,
error
)
{
return
rlp
.
EncodeToBytes
(
h
.
Header
)
}
// HeaderBlockInfo returns h as a BlockInfo implementation.
// HeaderBlockInfo returns h as a BlockInfo implementation.
func
HeaderBlockInfo
(
h
*
types
.
Header
)
BlockInfo
{
func
HeaderBlockInfo
(
h
*
types
.
Header
)
BlockInfo
{
return
headerBlockInfo
{
h
}
return
headerBlockInfo
{
h
}
...
...
op-node/rollup/derive/test/random.go
View file @
a13ff5f8
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
func
RandomL2Block
(
rng
*
rand
.
Rand
,
txCount
int
)
(
*
types
.
Block
,
[]
*
types
.
Receipt
)
{
func
RandomL2Block
(
rng
*
rand
.
Rand
,
txCount
int
)
(
*
types
.
Block
,
[]
*
types
.
Receipt
)
{
l1Block
:=
types
.
NewBlock
(
testutils
.
RandomHeader
(
rng
),
l1Block
:=
types
.
NewBlock
(
testutils
.
RandomHeader
(
rng
),
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
l1Block
,
eth
.
SystemConfig
{},
testutils
.
RandomBool
(
rng
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
eth
.
BlockToInfo
(
l1Block
)
,
eth
.
SystemConfig
{},
testutils
.
RandomBool
(
rng
))
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
"L1InfoDeposit: "
+
err
.
Error
())
panic
(
"L1InfoDeposit: "
+
err
.
Error
())
}
}
...
...
op-node/sources/eth_client.go
View file @
a13ff5f8
...
@@ -219,7 +219,7 @@ func (n numberID) CheckID(id eth.BlockID) error {
...
@@ -219,7 +219,7 @@ func (n numberID) CheckID(id eth.BlockID) error {
return
nil
return
nil
}
}
func
(
s
*
EthClient
)
headerCall
(
ctx
context
.
Context
,
method
string
,
id
rpcBlockID
)
(
*
Header
Info
,
error
)
{
func
(
s
*
EthClient
)
headerCall
(
ctx
context
.
Context
,
method
string
,
id
rpcBlockID
)
(
eth
.
Block
Info
,
error
)
{
var
header
*
rpcHeader
var
header
*
rpcHeader
err
:=
s
.
client
.
CallContext
(
ctx
,
&
header
,
method
,
id
.
Arg
(),
false
)
// headers are just blocks without txs
err
:=
s
.
client
.
CallContext
(
ctx
,
&
header
,
method
,
id
.
Arg
(),
false
)
// headers are just blocks without txs
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -239,7 +239,7 @@ func (s *EthClient) headerCall(ctx context.Context, method string, id rpcBlockID
...
@@ -239,7 +239,7 @@ func (s *EthClient) headerCall(ctx context.Context, method string, id rpcBlockID
return
info
,
nil
return
info
,
nil
}
}
func
(
s
*
EthClient
)
blockCall
(
ctx
context
.
Context
,
method
string
,
id
rpcBlockID
)
(
*
Header
Info
,
types
.
Transactions
,
error
)
{
func
(
s
*
EthClient
)
blockCall
(
ctx
context
.
Context
,
method
string
,
id
rpcBlockID
)
(
eth
.
Block
Info
,
types
.
Transactions
,
error
)
{
var
block
*
rpcBlock
var
block
*
rpcBlock
err
:=
s
.
client
.
CallContext
(
ctx
,
&
block
,
method
,
id
.
Arg
(),
true
)
err
:=
s
.
client
.
CallContext
(
ctx
,
&
block
,
method
,
id
.
Arg
(),
true
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -292,7 +292,7 @@ func (s *EthClient) ChainID(ctx context.Context) (*big.Int, error) {
...
@@ -292,7 +292,7 @@ func (s *EthClient) ChainID(ctx context.Context) (*big.Int, error) {
func
(
s
*
EthClient
)
InfoByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
error
)
{
func
(
s
*
EthClient
)
InfoByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
error
)
{
if
header
,
ok
:=
s
.
headersCache
.
Get
(
hash
);
ok
{
if
header
,
ok
:=
s
.
headersCache
.
Get
(
hash
);
ok
{
return
header
.
(
*
Header
Info
),
nil
return
header
.
(
eth
.
Block
Info
),
nil
}
}
return
s
.
headerCall
(
ctx
,
"eth_getBlockByHash"
,
hashID
(
hash
))
return
s
.
headerCall
(
ctx
,
"eth_getBlockByHash"
,
hashID
(
hash
))
}
}
...
@@ -310,7 +310,7 @@ func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.
...
@@ -310,7 +310,7 @@ func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.
func
(
s
*
EthClient
)
InfoAndTxsByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
,
error
)
{
func
(
s
*
EthClient
)
InfoAndTxsByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
,
error
)
{
if
header
,
ok
:=
s
.
headersCache
.
Get
(
hash
);
ok
{
if
header
,
ok
:=
s
.
headersCache
.
Get
(
hash
);
ok
{
if
txs
,
ok
:=
s
.
transactionsCache
.
Get
(
hash
);
ok
{
if
txs
,
ok
:=
s
.
transactionsCache
.
Get
(
hash
);
ok
{
return
header
.
(
*
Header
Info
),
txs
.
(
types
.
Transactions
),
nil
return
header
.
(
eth
.
Block
Info
),
txs
.
(
types
.
Transactions
),
nil
}
}
}
}
return
s
.
blockCall
(
ctx
,
"eth_getBlockByHash"
,
hashID
(
hash
))
return
s
.
blockCall
(
ctx
,
"eth_getBlockByHash"
,
hashID
(
hash
))
...
...
op-node/sources/types.go
View file @
a13ff5f8
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"math/big"
"math/big"
"strings"
"strings"
"github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256"
"github.com/holiman/uint256"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -33,69 +34,57 @@ type CallContextFn func(ctx context.Context, result any, method string, args ...
...
@@ -33,69 +34,57 @@ type CallContextFn func(ctx context.Context, result any, method string, args ...
//
//
// This way we minimize RPC calls, enable batching, and can choose to verify what the RPC gives us.
// This way we minimize RPC calls, enable batching, and can choose to verify what the RPC gives us.
//
HeaderInfo contains all the header-info required to implement the eth.BlockInfo interface,
//
headerInfo is a conversion type of types.Header turning it into a
//
used in the rollup state-transition, with pre-computed block hash
.
//
BlockInfo, but using a cached hash value
.
type
H
eaderInfo
struct
{
type
h
eaderInfo
struct
{
hash
common
.
Hash
hash
common
.
Hash
parentHash
common
.
Hash
*
types
.
Header
coinbase
common
.
Address
root
common
.
Hash
number
uint64
time
uint64
mixDigest
common
.
Hash
// a.k.a. the randomness field post-merge.
baseFee
*
big
.
Int
txHash
common
.
Hash
receiptHash
common
.
Hash
gasUsed
uint64
// withdrawalsRoot was added in Shapella and is thus optional
withdrawalsRoot
*
common
.
Hash
}
}
var
_
eth
.
BlockInfo
=
(
*
H
eaderInfo
)(
nil
)
var
_
eth
.
BlockInfo
=
(
*
h
eaderInfo
)(
nil
)
func
(
info
*
H
eaderInfo
)
Hash
()
common
.
Hash
{
func
(
h
h
eaderInfo
)
Hash
()
common
.
Hash
{
return
info
.
hash
return
h
.
hash
}
}
func
(
info
*
H
eaderInfo
)
ParentHash
()
common
.
Hash
{
func
(
h
h
eaderInfo
)
ParentHash
()
common
.
Hash
{
return
info
.
p
arentHash
return
h
.
Header
.
P
arentHash
}
}
func
(
info
*
H
eaderInfo
)
Coinbase
()
common
.
Address
{
func
(
h
h
eaderInfo
)
Coinbase
()
common
.
Address
{
return
info
.
c
oinbase
return
h
.
Header
.
C
oinbase
}
}
func
(
info
*
H
eaderInfo
)
Root
()
common
.
Hash
{
func
(
h
h
eaderInfo
)
Root
()
common
.
Hash
{
return
info
.
r
oot
return
h
.
Header
.
R
oot
}
}
func
(
info
*
H
eaderInfo
)
NumberU64
()
uint64
{
func
(
h
h
eaderInfo
)
NumberU64
()
uint64
{
return
info
.
number
return
h
.
Header
.
Number
.
Uint64
()
}
}
func
(
info
*
H
eaderInfo
)
Time
()
uint64
{
func
(
h
h
eaderInfo
)
Time
()
uint64
{
return
info
.
t
ime
return
h
.
Header
.
T
ime
}
}
func
(
info
*
H
eaderInfo
)
MixDigest
()
common
.
Hash
{
func
(
h
h
eaderInfo
)
MixDigest
()
common
.
Hash
{
return
info
.
m
ixDigest
return
h
.
Header
.
M
ixDigest
}
}
func
(
info
*
H
eaderInfo
)
BaseFee
()
*
big
.
Int
{
func
(
h
h
eaderInfo
)
BaseFee
()
*
big
.
Int
{
return
info
.
b
aseFee
return
h
.
Header
.
B
aseFee
}
}
func
(
info
*
HeaderInfo
)
ID
()
eth
.
BlockID
{
func
(
h
headerInfo
)
ReceiptHash
()
common
.
Hash
{
return
eth
.
BlockID
{
Hash
:
info
.
hash
,
Number
:
info
.
number
}
return
h
.
Header
.
ReceiptHash
}
}
func
(
info
*
HeaderInfo
)
ReceiptHash
()
common
.
Hash
{
func
(
h
headerInfo
)
GasUsed
()
uint64
{
return
info
.
receiptHash
return
h
.
Header
.
GasUsed
}
}
func
(
info
*
HeaderInfo
)
GasUsed
()
uint64
{
func
(
h
headerInfo
)
HeaderRLP
()
([]
byte
,
error
)
{
return
info
.
gasUsed
return
rlp
.
EncodeToBytes
(
h
.
Header
)
}
}
type
rpcHeader
struct
{
type
rpcHeader
struct
{
...
@@ -149,7 +138,12 @@ func (hdr *rpcHeader) checkPostMerge() error {
...
@@ -149,7 +138,12 @@ func (hdr *rpcHeader) checkPostMerge() error {
}
}
func
(
hdr
*
rpcHeader
)
computeBlockHash
()
common
.
Hash
{
func
(
hdr
*
rpcHeader
)
computeBlockHash
()
common
.
Hash
{
gethHeader
:=
types
.
Header
{
gethHeader
:=
hdr
.
createGethHeader
()
return
gethHeader
.
Hash
()
}
func
(
hdr
*
rpcHeader
)
createGethHeader
()
*
types
.
Header
{
return
&
types
.
Header
{
ParentHash
:
hdr
.
ParentHash
,
ParentHash
:
hdr
.
ParentHash
,
UncleHash
:
hdr
.
UncleHash
,
UncleHash
:
hdr
.
UncleHash
,
Coinbase
:
hdr
.
Coinbase
,
Coinbase
:
hdr
.
Coinbase
,
...
@@ -168,10 +162,9 @@ func (hdr *rpcHeader) computeBlockHash() common.Hash {
...
@@ -168,10 +162,9 @@ func (hdr *rpcHeader) computeBlockHash() common.Hash {
BaseFee
:
(
*
big
.
Int
)(
hdr
.
BaseFee
),
BaseFee
:
(
*
big
.
Int
)(
hdr
.
BaseFee
),
WithdrawalsHash
:
hdr
.
WithdrawalsRoot
,
WithdrawalsHash
:
hdr
.
WithdrawalsRoot
,
}
}
return
gethHeader
.
Hash
()
}
}
func
(
hdr
*
rpcHeader
)
Info
(
trustCache
bool
,
mustBePostMerge
bool
)
(
*
Header
Info
,
error
)
{
func
(
hdr
*
rpcHeader
)
Info
(
trustCache
bool
,
mustBePostMerge
bool
)
(
eth
.
Block
Info
,
error
)
{
if
mustBePostMerge
{
if
mustBePostMerge
{
if
err
:=
hdr
.
checkPostMerge
();
err
!=
nil
{
if
err
:=
hdr
.
checkPostMerge
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -182,22 +175,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo,
...
@@ -182,22 +175,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo,
return
nil
,
fmt
.
Errorf
(
"failed to verify block hash: computed %s but RPC said %s"
,
computed
,
hdr
.
Hash
)
return
nil
,
fmt
.
Errorf
(
"failed to verify block hash: computed %s but RPC said %s"
,
computed
,
hdr
.
Hash
)
}
}
}
}
return
&
headerInfo
{
hdr
.
Hash
,
hdr
.
createGethHeader
()},
nil
info
:=
HeaderInfo
{
hash
:
hdr
.
Hash
,
parentHash
:
hdr
.
ParentHash
,
coinbase
:
hdr
.
Coinbase
,
root
:
hdr
.
Root
,
number
:
uint64
(
hdr
.
Number
),
time
:
uint64
(
hdr
.
Time
),
mixDigest
:
hdr
.
MixDigest
,
baseFee
:
(
*
big
.
Int
)(
hdr
.
BaseFee
),
txHash
:
hdr
.
TxHash
,
receiptHash
:
hdr
.
ReceiptHash
,
gasUsed
:
uint64
(
hdr
.
GasUsed
),
withdrawalsRoot
:
hdr
.
WithdrawalsRoot
,
}
return
&
info
,
nil
}
}
type
rpcBlock
struct
{
type
rpcBlock
struct
{
...
@@ -215,7 +193,7 @@ func (block *rpcBlock) verify() error {
...
@@ -215,7 +193,7 @@ func (block *rpcBlock) verify() error {
return
nil
return
nil
}
}
func
(
block
*
rpcBlock
)
Info
(
trustCache
bool
,
mustBePostMerge
bool
)
(
*
Header
Info
,
types
.
Transactions
,
error
)
{
func
(
block
*
rpcBlock
)
Info
(
trustCache
bool
,
mustBePostMerge
bool
)
(
eth
.
Block
Info
,
types
.
Transactions
,
error
)
{
if
mustBePostMerge
{
if
mustBePostMerge
{
if
err
:=
block
.
checkPostMerge
();
err
!=
nil
{
if
err
:=
block
.
checkPostMerge
();
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
...
...
op-node/testutils/l1info.go
View file @
a13ff5f8
package
testutils
package
testutils
import
(
import
(
"errors"
"math/big"
"math/big"
"math/rand"
"math/rand"
...
@@ -22,6 +23,7 @@ type MockBlockInfo struct {
...
@@ -22,6 +23,7 @@ type MockBlockInfo struct {
InfoBaseFee
*
big
.
Int
InfoBaseFee
*
big
.
Int
InfoReceiptRoot
common
.
Hash
InfoReceiptRoot
common
.
Hash
InfoGasUsed
uint64
InfoGasUsed
uint64
InfoHeaderRLP
[]
byte
}
}
func
(
l
*
MockBlockInfo
)
Hash
()
common
.
Hash
{
func
(
l
*
MockBlockInfo
)
Hash
()
common
.
Hash
{
...
@@ -68,6 +70,13 @@ func (l *MockBlockInfo) ID() eth.BlockID {
...
@@ -68,6 +70,13 @@ func (l *MockBlockInfo) ID() eth.BlockID {
return
eth
.
BlockID
{
Hash
:
l
.
InfoHash
,
Number
:
l
.
InfoNum
}
return
eth
.
BlockID
{
Hash
:
l
.
InfoHash
,
Number
:
l
.
InfoNum
}
}
}
func
(
l
*
MockBlockInfo
)
HeaderRLP
()
([]
byte
,
error
)
{
if
l
.
InfoHeaderRLP
==
nil
{
return
nil
,
errors
.
New
(
"header rlp not available"
)
}
return
l
.
InfoHeaderRLP
,
nil
}
func
(
l
*
MockBlockInfo
)
BlockRef
()
eth
.
L1BlockRef
{
func
(
l
*
MockBlockInfo
)
BlockRef
()
eth
.
L1BlockRef
{
return
eth
.
L1BlockRef
{
return
eth
.
L1BlockRef
{
Hash
:
l
.
InfoHash
,
Hash
:
l
.
InfoHash
,
...
...
op-program/client/l1/cache_test.go
View file @
a13ff5f8
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"math/rand"
"math/rand"
"testing"
"testing"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
...
@@ -35,17 +36,17 @@ func TestCachingOracle_TransactionsByBlockHash(t *testing.T) {
...
@@ -35,17 +36,17 @@ func TestCachingOracle_TransactionsByBlockHash(t *testing.T) {
block
,
_
:=
testutils
.
RandomBlock
(
rng
,
3
)
block
,
_
:=
testutils
.
RandomBlock
(
rng
,
3
)
// Initial call retrieves from the stub
// Initial call retrieves from the stub
stub
.
blocks
[
block
.
Hash
()]
=
block
stub
.
blocks
[
block
.
Hash
()]
=
eth
.
BlockToInfo
(
block
)
stub
.
txs
[
block
.
Hash
()]
=
block
.
Transactions
()
stub
.
txs
[
block
.
Hash
()]
=
block
.
Transactions
()
actualBlock
,
actualTxs
:=
oracle
.
TransactionsByBlockHash
(
block
.
Hash
())
actualBlock
,
actualTxs
:=
oracle
.
TransactionsByBlockHash
(
block
.
Hash
())
require
.
Equal
(
t
,
block
,
actualBlock
)
require
.
Equal
(
t
,
eth
.
BlockToInfo
(
block
)
,
actualBlock
)
require
.
Equal
(
t
,
block
.
Transactions
(),
actualTxs
)
require
.
Equal
(
t
,
block
.
Transactions
(),
actualTxs
)
// Later calls should retrieve from cache
// Later calls should retrieve from cache
delete
(
stub
.
blocks
,
block
.
Hash
())
delete
(
stub
.
blocks
,
block
.
Hash
())
delete
(
stub
.
txs
,
block
.
Hash
())
delete
(
stub
.
txs
,
block
.
Hash
())
actualBlock
,
actualTxs
=
oracle
.
TransactionsByBlockHash
(
block
.
Hash
())
actualBlock
,
actualTxs
=
oracle
.
TransactionsByBlockHash
(
block
.
Hash
())
require
.
Equal
(
t
,
block
,
actualBlock
)
require
.
Equal
(
t
,
eth
.
BlockToInfo
(
block
)
,
actualBlock
)
require
.
Equal
(
t
,
block
.
Transactions
(),
actualTxs
)
require
.
Equal
(
t
,
block
.
Transactions
(),
actualTxs
)
}
}
...
@@ -56,16 +57,16 @@ func TestCachingOracle_ReceiptsByBlockHash(t *testing.T) {
...
@@ -56,16 +57,16 @@ func TestCachingOracle_ReceiptsByBlockHash(t *testing.T) {
block
,
rcpts
:=
testutils
.
RandomBlock
(
rng
,
3
)
block
,
rcpts
:=
testutils
.
RandomBlock
(
rng
,
3
)
// Initial call retrieves from the stub
// Initial call retrieves from the stub
stub
.
blocks
[
block
.
Hash
()]
=
block
stub
.
blocks
[
block
.
Hash
()]
=
eth
.
BlockToInfo
(
block
)
stub
.
rcpts
[
block
.
Hash
()]
=
rcpts
stub
.
rcpts
[
block
.
Hash
()]
=
rcpts
actualBlock
,
actualRcpts
:=
oracle
.
ReceiptsByBlockHash
(
block
.
Hash
())
actualBlock
,
actualRcpts
:=
oracle
.
ReceiptsByBlockHash
(
block
.
Hash
())
require
.
Equal
(
t
,
block
,
actualBlock
)
require
.
Equal
(
t
,
eth
.
BlockToInfo
(
block
)
,
actualBlock
)
require
.
EqualValues
(
t
,
rcpts
,
actualRcpts
)
require
.
EqualValues
(
t
,
rcpts
,
actualRcpts
)
// Later calls should retrieve from cache
// Later calls should retrieve from cache
delete
(
stub
.
blocks
,
block
.
Hash
())
delete
(
stub
.
blocks
,
block
.
Hash
())
delete
(
stub
.
rcpts
,
block
.
Hash
())
delete
(
stub
.
rcpts
,
block
.
Hash
())
actualBlock
,
actualRcpts
=
oracle
.
ReceiptsByBlockHash
(
block
.
Hash
())
actualBlock
,
actualRcpts
=
oracle
.
ReceiptsByBlockHash
(
block
.
Hash
())
require
.
Equal
(
t
,
block
,
actualBlock
)
require
.
Equal
(
t
,
eth
.
BlockToInfo
(
block
)
,
actualBlock
)
require
.
EqualValues
(
t
,
rcpts
,
actualRcpts
)
require
.
EqualValues
(
t
,
rcpts
,
actualRcpts
)
}
}
op-program/client/l1/client_test.go
View file @
a13ff5f8
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
...
@@ -24,7 +23,7 @@ var head = blockNum(1000)
...
@@ -24,7 +23,7 @@ var head = blockNum(1000)
func
TestInfoByHash
(
t
*
testing
.
T
)
{
func
TestInfoByHash
(
t
*
testing
.
T
)
{
client
,
oracle
:=
newClient
(
t
)
client
,
oracle
:=
newClient
(
t
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
expected
:=
&
sources
.
Header
Info
{}
expected
:=
&
testutils
.
MockBlock
Info
{}
oracle
.
blocks
[
hash
]
=
expected
oracle
.
blocks
[
hash
]
=
expected
info
,
err
:=
client
.
InfoByHash
(
context
.
Background
(),
hash
)
info
,
err
:=
client
.
InfoByHash
(
context
.
Background
(),
hash
)
...
@@ -35,7 +34,7 @@ func TestInfoByHash(t *testing.T) {
...
@@ -35,7 +34,7 @@ func TestInfoByHash(t *testing.T) {
func
TestL1BlockRefByHash
(
t
*
testing
.
T
)
{
func
TestL1BlockRefByHash
(
t
*
testing
.
T
)
{
client
,
oracle
:=
newClient
(
t
)
client
,
oracle
:=
newClient
(
t
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
header
:=
&
sources
.
Header
Info
{}
header
:=
&
testutils
.
MockBlock
Info
{}
oracle
.
blocks
[
hash
]
=
header
oracle
.
blocks
[
hash
]
=
header
expected
:=
eth
.
InfoToL1BlockRef
(
header
)
expected
:=
eth
.
InfoToL1BlockRef
(
header
)
...
@@ -47,7 +46,7 @@ func TestL1BlockRefByHash(t *testing.T) {
...
@@ -47,7 +46,7 @@ func TestL1BlockRefByHash(t *testing.T) {
func
TestFetchReceipts
(
t
*
testing
.
T
)
{
func
TestFetchReceipts
(
t
*
testing
.
T
)
{
client
,
oracle
:=
newClient
(
t
)
client
,
oracle
:=
newClient
(
t
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
expectedInfo
:=
&
sources
.
Header
Info
{}
expectedInfo
:=
&
testutils
.
MockBlock
Info
{}
expectedReceipts
:=
types
.
Receipts
{
expectedReceipts
:=
types
.
Receipts
{
&
types
.
Receipt
{},
&
types
.
Receipt
{},
}
}
...
@@ -63,7 +62,7 @@ func TestFetchReceipts(t *testing.T) {
...
@@ -63,7 +62,7 @@ func TestFetchReceipts(t *testing.T) {
func
TestInfoAndTxsByHash
(
t
*
testing
.
T
)
{
func
TestInfoAndTxsByHash
(
t
*
testing
.
T
)
{
client
,
oracle
:=
newClient
(
t
)
client
,
oracle
:=
newClient
(
t
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
hash
:=
common
.
HexToHash
(
"0xAABBCC"
)
expectedInfo
:=
&
sources
.
Header
Info
{}
expectedInfo
:=
&
testutils
.
MockBlock
Info
{}
expectedTxs
:=
types
.
Transactions
{
expectedTxs
:=
types
.
Transactions
{
&
types
.
Transaction
{},
&
types
.
Transaction
{},
}
}
...
...
op-program/host/l1/fetcher_test.go
View file @
a13ff5f8
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
cll1
"github.com/ethereum-optimism/optimism/op-program/client/l1"
cll1
"github.com/ethereum-optimism/optimism/op-program/client/l1"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -24,7 +25,7 @@ var _ Source = (*sources.L1Client)(nil)
...
@@ -24,7 +25,7 @@ var _ Source = (*sources.L1Client)(nil)
func
TestHeaderByHash
(
t
*
testing
.
T
)
{
func
TestHeaderByHash
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
expected
:=
&
sources
.
Header
Info
{}
expected
:=
&
testutils
.
MockBlock
Info
{}
source
:=
&
stubSource
{
nextInfo
:
expected
}
source
:=
&
stubSource
{
nextInfo
:
expected
}
oracle
:=
newFetchingOracle
(
t
,
source
)
oracle
:=
newFetchingOracle
(
t
,
source
)
...
@@ -54,7 +55,7 @@ func TestHeaderByHash(t *testing.T) {
...
@@ -54,7 +55,7 @@ func TestHeaderByHash(t *testing.T) {
func
TestTransactionsByHash
(
t
*
testing
.
T
)
{
func
TestTransactionsByHash
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
expectedInfo
:=
&
sources
.
Header
Info
{}
expectedInfo
:=
&
testutils
.
MockBlock
Info
{}
expectedTxs
:=
types
.
Transactions
{
expectedTxs
:=
types
.
Transactions
{
&
types
.
Transaction
{},
&
types
.
Transaction
{},
}
}
...
@@ -75,7 +76,7 @@ func TestTransactionsByHash(t *testing.T) {
...
@@ -75,7 +76,7 @@ func TestTransactionsByHash(t *testing.T) {
})
})
t
.
Run
(
"UnknownBlock_NoTxs"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"UnknownBlock_NoTxs"
,
func
(
t
*
testing
.
T
)
{
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
sources
.
Header
Info
{}})
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
testutils
.
MockBlock
Info
{}})
hash
:=
common
.
HexToHash
(
"0x4455"
)
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
TransactionsByBlockHash
(
hash
)
oracle
.
TransactionsByBlockHash
(
hash
)
...
@@ -96,7 +97,7 @@ func TestTransactionsByHash(t *testing.T) {
...
@@ -96,7 +97,7 @@ func TestTransactionsByHash(t *testing.T) {
func
TestReceiptsByHash
(
t
*
testing
.
T
)
{
func
TestReceiptsByHash
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Success"
,
func
(
t
*
testing
.
T
)
{
expectedInfo
:=
&
sources
.
Header
Info
{}
expectedInfo
:=
&
testutils
.
MockBlock
Info
{}
expectedRcpts
:=
types
.
Receipts
{
expectedRcpts
:=
types
.
Receipts
{
&
types
.
Receipt
{},
&
types
.
Receipt
{},
}
}
...
@@ -117,7 +118,7 @@ func TestReceiptsByHash(t *testing.T) {
...
@@ -117,7 +118,7 @@ func TestReceiptsByHash(t *testing.T) {
})
})
t
.
Run
(
"UnknownBlock_NoTxs"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"UnknownBlock_NoTxs"
,
func
(
t
*
testing
.
T
)
{
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
sources
.
Header
Info
{}})
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
testutils
.
MockBlock
Info
{}})
hash
:=
common
.
HexToHash
(
"0x4455"
)
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
ReceiptsByBlockHash
(
hash
)
oracle
.
ReceiptsByBlockHash
(
hash
)
...
...
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