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
b54be593
Unverified
Commit
b54be593
authored
Apr 12, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-program: Rename L1 oracle methods to be clear about what the hash is for.
parent
b1c9be0b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
34 deletions
+34
-34
client.go
op-program/client/l1/client.go
+6
-6
client_test.go
op-program/client/l1/client_test.go
+5
-5
oracle.go
op-program/client/l1/oracle.go
+6
-6
fetcher.go
op-program/host/l1/fetcher.go
+6
-6
fetcher_test.go
op-program/host/l1/fetcher_test.go
+11
-11
No files found.
op-program/client/l1/client.go
View file @
b54be593
...
...
@@ -23,7 +23,7 @@ type OracleL1Client struct {
}
func
NewOracleL1Client
(
logger
log
.
Logger
,
oracle
Oracle
,
l1Head
common
.
Hash
)
*
OracleL1Client
{
head
:=
eth
.
InfoToL1BlockRef
(
oracle
.
HeaderByHash
(
l1Head
))
head
:=
eth
.
InfoToL1BlockRef
(
oracle
.
HeaderBy
Block
Hash
(
l1Head
))
logger
.
Info
(
"L1 head loaded"
,
"hash"
,
head
.
Hash
,
"number"
,
head
.
Number
)
return
&
OracleL1Client
{
oracle
:
oracle
,
...
...
@@ -45,25 +45,25 @@ func (o OracleL1Client) L1BlockRefByNumber(ctx context.Context, number uint64) (
}
block
:=
o
.
head
for
block
.
Number
>
number
{
block
=
eth
.
InfoToL1BlockRef
(
o
.
oracle
.
HeaderByHash
(
block
.
ParentHash
))
block
=
eth
.
InfoToL1BlockRef
(
o
.
oracle
.
HeaderBy
Block
Hash
(
block
.
ParentHash
))
}
return
block
,
nil
}
func
(
o
OracleL1Client
)
L1BlockRefByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
L1BlockRef
,
error
)
{
return
eth
.
InfoToL1BlockRef
(
o
.
oracle
.
HeaderByHash
(
hash
)),
nil
return
eth
.
InfoToL1BlockRef
(
o
.
oracle
.
HeaderBy
Block
Hash
(
hash
)),
nil
}
func
(
o
OracleL1Client
)
InfoByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
error
)
{
return
o
.
oracle
.
HeaderByHash
(
hash
),
nil
return
o
.
oracle
.
HeaderBy
Block
Hash
(
hash
),
nil
}
func
(
o
OracleL1Client
)
FetchReceipts
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
,
error
)
{
info
,
rcpts
:=
o
.
oracle
.
ReceiptsByHash
(
blockHash
)
info
,
rcpts
:=
o
.
oracle
.
ReceiptsBy
Block
Hash
(
blockHash
)
return
info
,
rcpts
,
nil
}
func
(
o
OracleL1Client
)
InfoAndTxsByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
,
error
)
{
info
,
txs
:=
o
.
oracle
.
TransactionsByHash
(
hash
)
info
,
txs
:=
o
.
oracle
.
TransactionsBy
Block
Hash
(
hash
)
return
info
,
txs
,
nil
}
op-program/client/l1/client_test.go
View file @
b54be593
...
...
@@ -169,7 +169,7 @@ type stubOracle struct {
rcpts
map
[
common
.
Hash
]
types
.
Receipts
}
func
(
o
stubOracle
)
HeaderByHash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
{
func
(
o
stubOracle
)
HeaderBy
Block
Hash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
{
info
,
ok
:=
o
.
blocks
[
blockHash
]
if
!
ok
{
o
.
t
.
Fatalf
(
"unknown block %s"
,
blockHash
)
...
...
@@ -177,20 +177,20 @@ func (o stubOracle) HeaderByHash(blockHash common.Hash) eth.BlockInfo {
return
info
}
func
(
o
stubOracle
)
TransactionsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
{
func
(
o
stubOracle
)
TransactionsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
{
txs
,
ok
:=
o
.
txs
[
blockHash
]
if
!
ok
{
o
.
t
.
Fatalf
(
"unknown txs %s"
,
blockHash
)
}
return
o
.
HeaderByHash
(
blockHash
),
txs
return
o
.
HeaderBy
Block
Hash
(
blockHash
),
txs
}
func
(
o
stubOracle
)
ReceiptsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
{
func
(
o
stubOracle
)
ReceiptsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
{
rcpts
,
ok
:=
o
.
rcpts
[
blockHash
]
if
!
ok
{
o
.
t
.
Fatalf
(
"unknown rcpts %s"
,
blockHash
)
}
return
o
.
HeaderByHash
(
blockHash
),
rcpts
return
o
.
HeaderBy
Block
Hash
(
blockHash
),
rcpts
}
func
blockNum
(
num
uint64
)
eth
.
BlockInfo
{
...
...
op-program/client/l1/oracle.go
View file @
b54be593
...
...
@@ -7,12 +7,12 @@ import (
)
type
Oracle
interface
{
// HeaderByHash retrieves the block header with the given hash.
HeaderByHash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
// HeaderBy
Block
Hash retrieves the block header with the given hash.
HeaderBy
Block
Hash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
// TransactionsByHash retrieves the transactions from the block with the given hash.
TransactionsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
// TransactionsBy
Block
Hash retrieves the transactions from the block with the given hash.
TransactionsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
// ReceiptsByHash retrieves the receipts from the block with the given hash.
ReceiptsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
// ReceiptsBy
Block
Hash retrieves the receipts from the block with the given hash.
ReceiptsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
}
op-program/host/l1/fetcher.go
View file @
b54be593
...
...
@@ -30,8 +30,8 @@ func NewFetchingL1Oracle(ctx context.Context, logger log.Logger, source Source)
}
}
func
(
o
FetchingL1Oracle
)
HeaderByHash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
{
o
.
logger
.
Trace
(
"HeaderByHash"
,
"hash"
,
blockHash
)
func
(
o
FetchingL1Oracle
)
HeaderBy
Block
Hash
(
blockHash
common
.
Hash
)
eth
.
BlockInfo
{
o
.
logger
.
Trace
(
"HeaderBy
Block
Hash"
,
"hash"
,
blockHash
)
info
,
err
:=
o
.
source
.
InfoByHash
(
o
.
ctx
,
blockHash
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"retrieve block %s: %w"
,
blockHash
,
err
))
...
...
@@ -42,8 +42,8 @@ func (o FetchingL1Oracle) HeaderByHash(blockHash common.Hash) eth.BlockInfo {
return
info
}
func
(
o
FetchingL1Oracle
)
TransactionsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
{
o
.
logger
.
Trace
(
"TransactionsByHash"
,
"hash"
,
blockHash
)
func
(
o
FetchingL1Oracle
)
TransactionsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Transactions
)
{
o
.
logger
.
Trace
(
"TransactionsBy
Block
Hash"
,
"hash"
,
blockHash
)
info
,
txs
,
err
:=
o
.
source
.
InfoAndTxsByHash
(
o
.
ctx
,
blockHash
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"retrieve transactions for block %s: %w"
,
blockHash
,
err
))
...
...
@@ -54,8 +54,8 @@ func (o FetchingL1Oracle) TransactionsByHash(blockHash common.Hash) (eth.BlockIn
return
info
,
txs
}
func
(
o
FetchingL1Oracle
)
ReceiptsByHash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
{
o
.
logger
.
Trace
(
"ReceiptsByHash"
,
"hash"
,
blockHash
)
func
(
o
FetchingL1Oracle
)
ReceiptsBy
Block
Hash
(
blockHash
common
.
Hash
)
(
eth
.
BlockInfo
,
types
.
Receipts
)
{
o
.
logger
.
Trace
(
"ReceiptsBy
Block
Hash"
,
"hash"
,
blockHash
)
info
,
rcpts
,
err
:=
o
.
source
.
FetchReceipts
(
o
.
ctx
,
blockHash
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"retrieve receipts for block %s: %w"
,
blockHash
,
err
))
...
...
op-program/host/l1/fetcher_test.go
View file @
b54be593
...
...
@@ -28,7 +28,7 @@ func TestHeaderByHash(t *testing.T) {
source
:=
&
stubSource
{
nextInfo
:
expected
}
oracle
:=
newFetchingOracle
(
t
,
source
)
actual
:=
oracle
.
HeaderByHash
(
expected
.
Hash
())
actual
:=
oracle
.
HeaderBy
Block
Hash
(
expected
.
Hash
())
require
.
Equal
(
t
,
expected
,
actual
)
})
...
...
@@ -36,7 +36,7 @@ func TestHeaderByHash(t *testing.T) {
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{})
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
HeaderByHash
(
hash
)
oracle
.
HeaderBy
Block
Hash
(
hash
)
})
})
...
...
@@ -47,7 +47,7 @@ func TestHeaderByHash(t *testing.T) {
hash
:=
common
.
HexToHash
(
"0x8888"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"retrieve block %s: %w"
,
hash
,
err
)
.
Error
(),
func
()
{
oracle
.
HeaderByHash
(
hash
)
oracle
.
HeaderBy
Block
Hash
(
hash
)
})
})
}
...
...
@@ -61,7 +61,7 @@ func TestTransactionsByHash(t *testing.T) {
source
:=
&
stubSource
{
nextInfo
:
expectedInfo
,
nextTxs
:
expectedTxs
}
oracle
:=
newFetchingOracle
(
t
,
source
)
info
,
txs
:=
oracle
.
TransactionsByHash
(
expectedInfo
.
Hash
())
info
,
txs
:=
oracle
.
TransactionsBy
Block
Hash
(
expectedInfo
.
Hash
())
require
.
Equal
(
t
,
expectedInfo
,
info
)
require
.
Equal
(
t
,
expectedTxs
,
txs
)
})
...
...
@@ -70,7 +70,7 @@ func TestTransactionsByHash(t *testing.T) {
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{})
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
TransactionsByHash
(
hash
)
oracle
.
TransactionsBy
Block
Hash
(
hash
)
})
})
...
...
@@ -78,7 +78,7 @@ func TestTransactionsByHash(t *testing.T) {
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
sources
.
HeaderInfo
{}})
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
TransactionsByHash
(
hash
)
oracle
.
TransactionsBy
Block
Hash
(
hash
)
})
})
...
...
@@ -89,7 +89,7 @@ func TestTransactionsByHash(t *testing.T) {
hash
:=
common
.
HexToHash
(
"0x8888"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"retrieve transactions for block %s: %w"
,
hash
,
err
)
.
Error
(),
func
()
{
oracle
.
TransactionsByHash
(
hash
)
oracle
.
TransactionsBy
Block
Hash
(
hash
)
})
})
}
...
...
@@ -103,7 +103,7 @@ func TestReceiptsByHash(t *testing.T) {
source
:=
&
stubSource
{
nextInfo
:
expectedInfo
,
nextRcpts
:
expectedRcpts
}
oracle
:=
newFetchingOracle
(
t
,
source
)
info
,
rcpts
:=
oracle
.
ReceiptsByHash
(
expectedInfo
.
Hash
())
info
,
rcpts
:=
oracle
.
ReceiptsBy
Block
Hash
(
expectedInfo
.
Hash
())
require
.
Equal
(
t
,
expectedInfo
,
info
)
require
.
Equal
(
t
,
expectedRcpts
,
rcpts
)
})
...
...
@@ -112,7 +112,7 @@ func TestReceiptsByHash(t *testing.T) {
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{})
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
ReceiptsByHash
(
hash
)
oracle
.
ReceiptsBy
Block
Hash
(
hash
)
})
})
...
...
@@ -120,7 +120,7 @@ func TestReceiptsByHash(t *testing.T) {
oracle
:=
newFetchingOracle
(
t
,
&
stubSource
{
nextInfo
:
&
sources
.
HeaderInfo
{}})
hash
:=
common
.
HexToHash
(
"0x4455"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"unknown block: %s"
,
hash
)
.
Error
(),
func
()
{
oracle
.
ReceiptsByHash
(
hash
)
oracle
.
ReceiptsBy
Block
Hash
(
hash
)
})
})
...
...
@@ -131,7 +131,7 @@ func TestReceiptsByHash(t *testing.T) {
hash
:=
common
.
HexToHash
(
"0x8888"
)
require
.
PanicsWithError
(
t
,
fmt
.
Errorf
(
"retrieve receipts for block %s: %w"
,
hash
,
err
)
.
Error
(),
func
()
{
oracle
.
ReceiptsByHash
(
hash
)
oracle
.
ReceiptsBy
Block
Hash
(
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