-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5452 from ethereum-optimism/aj/fpp-store-fetched-…
…data op-program: Populate preimage store
- Loading branch information
Showing
9 changed files
with
675 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package sources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/rawdb" | ||
) | ||
|
||
type DebugClient struct { | ||
callContext CallContextFn | ||
} | ||
|
||
func NewDebugClient(callContext CallContextFn) *DebugClient { | ||
return &DebugClient{callContext} | ||
} | ||
|
||
func (o *DebugClient) NodeByHash(ctx context.Context, hash common.Hash) ([]byte, error) { | ||
// MPT nodes are stored as the hash of the node (with no prefix) | ||
node, err := o.dbGet(ctx, hash[:]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to retrieve state MPT node: %w", err) | ||
} | ||
return node, nil | ||
} | ||
|
||
func (o *DebugClient) CodeByHash(ctx context.Context, hash common.Hash) ([]byte, error) { | ||
// First try retrieving with the new code prefix | ||
code, err := o.dbGet(ctx, append(append(make([]byte, 0), rawdb.CodePrefix...), hash[:]...)) | ||
if err != nil { | ||
// Fallback to the legacy un-prefixed version | ||
code, err = o.dbGet(ctx, hash[:]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to retrieve contract code, using new and legacy keys, with codehash %s: %w", hash, err) | ||
} | ||
} | ||
return code, nil | ||
} | ||
|
||
func (o *DebugClient) dbGet(ctx context.Context, key []byte) ([]byte, error) { | ||
var node hexutil.Bytes | ||
err := o.callContext(ctx, &node, "debug_dbGet", hexutil.Encode(key)) | ||
if err != nil { | ||
return nil, fmt.Errorf("fetch error %x: %w", key, err) | ||
} | ||
return node, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package testutils | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockDebugClient struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *MockDebugClient) ExpectNodeByHash(hash common.Hash, res []byte, err error) { | ||
m.Mock.On("NodeByHash", hash).Once().Return(res, &err) | ||
} | ||
|
||
func (m *MockDebugClient) NodeByHash(ctx context.Context, hash common.Hash) ([]byte, error) { | ||
out := m.Mock.MethodCalled("NodeByHash", hash) | ||
return out[0].([]byte), *out[1].(*error) | ||
} | ||
|
||
func (m *MockDebugClient) ExpectCodeByHash(hash common.Hash, res []byte, err error) { | ||
m.Mock.On("CodeByHash", hash).Once().Return(res, &err) | ||
} | ||
|
||
func (m *MockDebugClient) CodeByHash(ctx context.Context, hash common.Hash) ([]byte, error) { | ||
out := m.Mock.MethodCalled("CodeByHash", hash) | ||
return out[0].([]byte), *out[1].(*error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.