Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(backend): allow pre eip-155 txs #1346

Merged
merged 12 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ type CosmosApp interface {
// It also includes wrapped versions of the Geth Miner and TxPool.
type Polaris struct {
*eth.ExecutionLayer

// WrappedMiner is a wrapped version of the Miner component.
WrappedMiner *miner.Miner
// WrappedTxPool is a wrapped version of the Mempool component.
WrappedTxPool *txpool.Mempool
// WrappedBlockchain is a wrapped version of the Blockchain component.
WrappedBlockchain *chain.WrappedBlockchain

// logger is the underlying logger supplied by the sdk.
logger log.Logger
}
Expand All @@ -97,7 +95,8 @@ func New(
}

p.ExecutionLayer, err = eth.New(
"geth", cfg, host, engine, LoggerFuncHandler(logger),
"geth", cfg, host, engine, cfg.Node.AllowUnprotectedTxs,
LoggerFuncHandler(logger),
)
if err != nil {
panic(err)
Expand Down
10 changes: 5 additions & 5 deletions eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ type (
// as parameters. It returns a pointer to the ExecutionLayer and an error if any.
func New(
client string, cfg any, host pcore.PolarisHostChain,
engine consensus.Engine, logHandler log.Handler,
engine consensus.Engine, allowUnprotectedTxs bool, logHandler log.Handler,
Comment on lines 97 to +100
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowUnprotectedTxs parameter has been added to the New function without accompanying documentation or comments. It is important to document new parameters to explain their purpose and usage for future maintainability and clarity.

  client string, cfg any, host pcore.PolarisHostChain,
+ // allowUnprotectedTxs enables the processing of transactions without EIP-155 protection.
  engine consensus.Engine, allowUnprotectedTxs bool, logHandler log.Handler,

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// as parameters. It returns a pointer to the ExecutionLayer and an error if any.
func New(
client string, cfg any, host pcore.PolarisHostChain,
engine consensus.Engine, logHandler log.Handler,
engine consensus.Engine, allowUnprotectedTxs bool, logHandler log.Handler,
// as parameters. It returns a pointer to the ExecutionLayer and an error if any.
func New(
client string, cfg any, host pcore.PolarisHostChain,
// allowUnprotectedTxs enables the processing of transactions without EIP-155 protection.
engine consensus.Engine, allowUnprotectedTxs bool, logHandler log.Handler,

) (*ExecutionLayer, error) {
clientFactories := map[string]func(
any, pcore.PolarisHostChain, consensus.Engine, log.Handler,
any, pcore.PolarisHostChain, consensus.Engine, bool, log.Handler,
) (*ExecutionLayer, error){
"geth": newGethExecutionLayer,
}
Expand All @@ -110,14 +110,14 @@ func New(
return nil, fmt.Errorf("unknown execution layer: %s", client)
}

return factory(cfg, host, engine, logHandler)
return factory(cfg, host, engine, allowUnprotectedTxs, logHandler)
}

// newGethExecutionLayer creates a new geth execution layer.
// It returns a pointer to the ExecutionLayer and an error if any.
func newGethExecutionLayer(
anyCfg any, host pcore.PolarisHostChain,
engine consensus.Engine, logHandler log.Handler,
engine consensus.Engine, allowUnprotectedTxs bool, logHandler log.Handler,
) (*ExecutionLayer, error) {
cfg, ok := anyCfg.(*Config)
if !ok {
Expand All @@ -134,7 +134,7 @@ func newGethExecutionLayer(
gethNode.SetP2PDisabled(true)

// Create a new Polaris backend
backend := polar.New(&cfg.Polar, host, engine, gethNode, logHandler)
backend := polar.New(&cfg.Polar, host, engine, gethNode, allowUnprotectedTxs, logHandler)

// Return a new ExecutionLayer with the created gethNode and backend
return &ExecutionLayer{
Expand Down
25 changes: 13 additions & 12 deletions eth/polar/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ type (

// backend represents the backend for the JSON-RPC service.
type backend struct {
polar *Polaris
cfg *Config
extRPCEnabled bool
gpo *gasprice.Oracle
logger log.Logger
polar *Polaris
cfg *Config
extRPCEnabled bool
allowUnprotectedTxs bool
gpo *gasprice.Oracle
logger log.Logger
}

// ==============================================================================
Expand All @@ -87,14 +88,16 @@ type backend struct {
func NewAPIBackend(
polar *Polaris,
extRPCEnabled bool,
allowUnprotectedTxs bool,
cfg *Config,
) APIBackend {
b := &backend{

polar: polar,
cfg: cfg,
extRPCEnabled: extRPCEnabled,
logger: log.Root(),
polar: polar,
cfg: cfg,
extRPCEnabled: extRPCEnabled,
allowUnprotectedTxs: allowUnprotectedTxs,
logger: log.Root(),
}

if cfg.GPO.Default == nil {
Expand Down Expand Up @@ -173,10 +176,8 @@ func (b *backend) RPCTxFeeCap() float64 {
}

// UnprotectedAllowed returns whether unprotected transactions are alloweds.
// We will consider implementing these later, But our opinion is that
// there is no reason in 2023 not to use these.
func (b *backend) UnprotectedAllowed() bool {
return false
return b.allowUnprotectedTxs
}

// ==============================================================================
Expand Down
3 changes: 2 additions & 1 deletion eth/polar/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func New(
host core.PolarisHostChain,
engine consensus.Engine,
stack executionLayerNode,
allowUnprotectedTxs bool,
logHandler log.Handler,
) *Polaris {
// When creating a Polaris EVM, we allow the implementing chain
Expand Down Expand Up @@ -116,7 +117,7 @@ func New(
}

// Build the backend api object.
pl.apiBackend = NewAPIBackend(pl, stack.ExtRPCEnabled(), pl.config)
pl.apiBackend = NewAPIBackend(pl, stack.ExtRPCEnabled(), allowUnprotectedTxs, pl.config)

// Run safety message for feedback to the user if they are running
// with development configs.
Expand Down