Commit cab9dfe9 authored by inphi's avatar inphi

rename L2OutputRoot

parent e93af705
......@@ -44,11 +44,11 @@ func (m *MockL2Client) ExpectSystemConfigByL2Hash(hash common.Hash, cfg eth.Syst
m.Mock.On("SystemConfigByL2Hash", hash).Once().Return(cfg, &err)
}
func (m *MockL2Client) L2OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
out := m.Mock.MethodCalled("L2OutputByRoot", root)
func (m *MockL2Client) OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
out := m.Mock.MethodCalled("OutputByRoot", root)
return out[0].(eth.Output), *out[1].(*error)
}
func (m *MockL2Client) ExpectL2OutputByRoot(root common.Hash, output eth.Output, err error) {
m.Mock.On("L2OutputByRoot", root).Once().Return(output, &err)
func (m *MockL2Client) ExpectOutputByRoot(root common.Hash, output eth.Output, err error) {
m.Mock.On("OutputByRoot", root).Once().Return(output, &err)
}
......@@ -65,12 +65,12 @@ func (o *CachingOracle) BlockByHash(blockHash common.Hash) *types.Block {
return block
}
func (o *CachingOracle) L2OutputByRoot(root common.Hash) eth.Output {
func (o *CachingOracle) OutputByRoot(root common.Hash) eth.Output {
output, ok := o.outputs.Get(root)
if ok {
return output
}
output = o.oracle.L2OutputByRoot(root)
output = o.oracle.OutputByRoot(root)
o.outputs.Add(root, output)
return output
}
......@@ -41,7 +41,7 @@ type OracleBackedL2Chain struct {
var _ engineapi.EngineBackend = (*OracleBackedL2Chain)(nil)
func NewOracleBackedL2Chain(logger log.Logger, oracle Oracle, chainCfg *params.ChainConfig, l2OutputRoot common.Hash) (*OracleBackedL2Chain, error) {
output := oracle.L2OutputByRoot(l2OutputRoot)
output := oracle.OutputByRoot(l2OutputRoot)
outputV0, ok := output.(*eth.OutputV0)
if !ok {
return nil, fmt.Errorf("unsupported L2 output version: %d", output.Version())
......
......@@ -33,7 +33,7 @@ type Oracle interface {
// BlockByHash retrieves the block with the given hash.
BlockByHash(blockHash common.Hash) *types.Block
L2OutputByRoot(root common.Hash) eth.Output
OutputByRoot(root common.Hash) eth.Output
}
// PreimageOracle implements Oracle using by interfacing with the pure preimage.Oracle
......@@ -88,7 +88,7 @@ func (p *PreimageOracle) CodeByHash(codeHash common.Hash) []byte {
return p.oracle.Get(preimage.Keccak256Key(codeHash))
}
func (p *PreimageOracle) L2OutputByRoot(l2OutputRoot common.Hash) eth.Output {
func (p *PreimageOracle) OutputByRoot(l2OutputRoot common.Hash) eth.Output {
p.hint.Hint(L2OutputHint(l2OutputRoot))
data := p.oracle.Get(preimage.Keccak256Key(l2OutputRoot))
output, err := eth.UnmarshalOutput(data)
......
......@@ -59,7 +59,7 @@ func (o StubBlockOracle) BlockByHash(blockHash common.Hash) *types.Block {
return block
}
func (o StubBlockOracle) L2OutputByRoot(root common.Hash) eth.Output {
func (o StubBlockOracle) OutputByRoot(root common.Hash) eth.Output {
output, ok := o.Outputs[root]
if !ok {
o.t.Fatalf("requested unknown output root %s", root)
......
......@@ -47,12 +47,12 @@ var (
}
L2Head = &cli.StringFlag{
Name: "l2.head",
Usage: "Hash of the agreed L2 block to start derivation from",
Usage: "Hash of the L2 block at l2.outputroot",
EnvVars: prefixEnvVars("L2_HEAD"),
}
L2OutputRoot = &cli.StringFlag{
Name: "l2.outputroot",
Usage: "L2 Output Root at l2.head",
Usage: "Agreed L2 Output Root to start derivation from",
EnvVars: prefixEnvVars("L2_OUTPUT_ROOT"),
}
L2Claim = &cli.StringFlag{
......
......@@ -17,6 +17,7 @@ import (
type L2Client struct {
*sources.L2Client
// l2Head is the L2 block hash that we use to fetch L2 output
l2Head common.Hash
}
......@@ -36,7 +37,7 @@ func NewL2Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
}, nil
}
func (s *L2Client) L2OutputByRoot(ctx context.Context, l2OutputRoot common.Hash) (eth.Output, error) {
func (s *L2Client) OutputByRoot(ctx context.Context, l2OutputRoot common.Hash) (eth.Output, error) {
output, err := s.outputAtBlock(ctx, s.l2Head)
if err != nil {
return nil, err
......
......@@ -29,7 +29,7 @@ type L2Source interface {
InfoAndTxsByHash(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Transactions, error)
NodeByHash(ctx context.Context, hash common.Hash) ([]byte, error)
CodeByHash(ctx context.Context, hash common.Hash) ([]byte, error)
L2OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error)
OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error)
}
type Prefetcher struct {
......@@ -126,7 +126,7 @@ func (p *Prefetcher) prefetch(ctx context.Context, hint string) error {
}
return p.kvStore.Put(preimage.Keccak256Key(hash).PreimageKey(), code)
case l2.HintL2Output:
output, err := p.l2Fetcher.L2OutputByRoot(ctx, hash)
output, err := p.l2Fetcher.OutputByRoot(ctx, hash)
if err != nil {
return fmt.Errorf("failed to fetch L2 output root %s: %w", hash, err)
}
......
......@@ -125,10 +125,10 @@ func (s *RetryingL2Source) CodeByHash(ctx context.Context, hash common.Hash) ([]
return code, err
}
func (s *RetryingL2Source) L2OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
func (s *RetryingL2Source) OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
var output eth.Output
err := backoff.DoCtx(ctx, maxAttempts, s.strategy, func() error {
o, err := s.source.L2OutputByRoot(ctx, root)
o, err := s.source.OutputByRoot(ctx, root)
if err != nil {
s.logger.Warn("Failed to fetch l2 output", "root", root, "err", err)
return err
......
......@@ -229,13 +229,13 @@ func (m *MockL2Source) ExpectCodeByHash(hash common.Hash, code []byte, err error
m.Mock.On("CodeByHash", hash).Once().Return(code, &err)
}
func (m *MockL2Source) L2OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
out := m.Mock.MethodCalled("L2OutputByRoot", root)
func (m *MockL2Source) OutputByRoot(ctx context.Context, root common.Hash) (eth.Output, error) {
out := m.Mock.MethodCalled("OutputByRoot", root)
return out[0].(eth.Output), *out[1].(*error)
}
func (m *MockL2Source) ExpectL2OutputByRoot(root common.Hash, output eth.Output, err error) {
m.Mock.On("L2OutputByRoot", root).Once().Return(output, &err)
func (m *MockL2Source) ExpectOutputByRoot(root common.Hash, output eth.Output, err error) {
m.Mock.On("OutputByRoot", root).Once().Return(output, &err)
}
var _ L2Source = (*MockL2Source)(nil)
......@@ -110,7 +110,7 @@ func Run(l1RpcUrl string, l2RpcUrl string, l2OracleAddr common.Address) error {
return fmt.Errorf("retrieve agreed output: %w", err)
}
if agreedOutput.OutputRoot == output.OutputRoot {
// TODO(inphi): Don't return here but keep searching preceeding blocks for a different output
// TODO(inphi): Don't return here but keep searching preceding blocks for a different output
return fmt.Errorf("agreed output is the same as the output claim")
}
......
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