Commit b54be593 authored by Adrian Sutton's avatar Adrian Sutton

op-program: Rename L1 oracle methods to be clear about what the hash is for.

parent b1c9be0b
......@@ -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.HeaderByBlockHash(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.HeaderByBlockHash(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.HeaderByBlockHash(hash)), nil
}
func (o OracleL1Client) InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error) {
return o.oracle.HeaderByHash(hash), nil
return o.oracle.HeaderByBlockHash(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.ReceiptsByBlockHash(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.TransactionsByBlockHash(hash)
return info, txs, nil
}
......@@ -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) HeaderByBlockHash(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) TransactionsByBlockHash(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.HeaderByBlockHash(blockHash), txs
}
func (o stubOracle) ReceiptsByHash(blockHash common.Hash) (eth.BlockInfo, types.Receipts) {
func (o stubOracle) ReceiptsByBlockHash(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.HeaderByBlockHash(blockHash), rcpts
}
func blockNum(num uint64) eth.BlockInfo {
......
......@@ -7,12 +7,12 @@ import (
)
type Oracle interface {
// HeaderByHash retrieves the block header with the given hash.
HeaderByHash(blockHash common.Hash) eth.BlockInfo
// HeaderByBlockHash retrieves the block header with the given hash.
HeaderByBlockHash(blockHash common.Hash) eth.BlockInfo
// TransactionsByHash retrieves the transactions from the block with the given hash.
TransactionsByHash(blockHash common.Hash) (eth.BlockInfo, types.Transactions)
// TransactionsByBlockHash retrieves the transactions from the block with the given hash.
TransactionsByBlockHash(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)
// ReceiptsByBlockHash retrieves the receipts from the block with the given hash.
ReceiptsByBlockHash(blockHash common.Hash) (eth.BlockInfo, types.Receipts)
}
......@@ -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) HeaderByBlockHash(blockHash common.Hash) eth.BlockInfo {
o.logger.Trace("HeaderByBlockHash", "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) TransactionsByBlockHash(blockHash common.Hash) (eth.BlockInfo, types.Transactions) {
o.logger.Trace("TransactionsByBlockHash", "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) ReceiptsByBlockHash(blockHash common.Hash) (eth.BlockInfo, types.Receipts) {
o.logger.Trace("ReceiptsByBlockHash", "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))
......
......@@ -28,7 +28,7 @@ func TestHeaderByHash(t *testing.T) {
source := &stubSource{nextInfo: expected}
oracle := newFetchingOracle(t, source)
actual := oracle.HeaderByHash(expected.Hash())
actual := oracle.HeaderByBlockHash(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.HeaderByBlockHash(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.HeaderByBlockHash(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.TransactionsByBlockHash(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.TransactionsByBlockHash(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.TransactionsByBlockHash(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.TransactionsByBlockHash(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.ReceiptsByBlockHash(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.ReceiptsByBlockHash(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.ReceiptsByBlockHash(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.ReceiptsByBlockHash(hash)
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment