forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-conductor: adds execution and node rpc proxy backends (ethereum-op…
- Loading branch information
Showing
14 changed files
with
233 additions
and
44 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
var ExecutionRPCNamespace = "eth" | ||
|
||
// ExecutionProxyBackend implements an execution rpc proxy with a leadership check before each call. | ||
type ExecutionProxyBackend struct { | ||
log log.Logger | ||
con conductor | ||
client *ethclient.Client | ||
} | ||
|
||
var _ ExecutionProxyAPI = (*ExecutionProxyBackend)(nil) | ||
|
||
func NewExecutionProxyBackend(log log.Logger, con conductor, client *ethclient.Client) *ExecutionProxyBackend { | ||
return &ExecutionProxyBackend{ | ||
log: log, | ||
con: con, | ||
client: client, | ||
} | ||
} | ||
|
||
func (api *ExecutionProxyBackend) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { | ||
block, err := api.client.BlockByNumber(ctx, number) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !api.con.Leader(ctx) { | ||
return nil, ErrNotLeader | ||
} | ||
return block, 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,61 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/eth" | ||
"github.com/ethereum-optimism/optimism/op-service/sources" | ||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
var NodeRPCNamespace = "optimism" | ||
|
||
// NodeProxyBackend implements a node rpc proxy with a leadership check before each call. | ||
type NodeProxyBackend struct { | ||
log log.Logger | ||
con conductor | ||
client *sources.RollupClient | ||
} | ||
|
||
var _ NodeProxyAPI = (*NodeProxyBackend)(nil) | ||
|
||
func NewNodeProxyBackend(log log.Logger, con conductor, client *sources.RollupClient) *NodeProxyBackend { | ||
return &NodeProxyBackend{ | ||
log: log, | ||
con: con, | ||
client: client, | ||
} | ||
} | ||
|
||
func (api *NodeProxyBackend) SyncStatus(ctx context.Context) (*eth.SyncStatus, error) { | ||
status, err := api.client.SyncStatus(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !api.con.Leader(ctx) { | ||
return nil, ErrNotLeader | ||
} | ||
return status, err | ||
} | ||
|
||
func (api *NodeProxyBackend) OutputAtBlock(ctx context.Context, blockNum uint64) (*eth.OutputResponse, error) { | ||
output, err := api.client.OutputAtBlock(ctx, blockNum) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !api.con.Leader(ctx) { | ||
return nil, ErrNotLeader | ||
} | ||
return output, nil | ||
} | ||
|
||
func (api *NodeProxyBackend) SequencerActive(ctx context.Context) (bool, error) { | ||
active, err := api.client.SequencerActive(ctx) | ||
if err != nil { | ||
return false, err | ||
} | ||
if !api.con.Leader(ctx) { | ||
return false, ErrNotLeader | ||
} | ||
return active, err | ||
} |
Oops, something went wrong.