Skip to content

Commit

Permalink
support for forwarding sendRawTransactionConditional to seqRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdiallam committed Sep 6, 2024
1 parent cc96057 commit eec006a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
7 changes: 1 addition & 6 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@ func (s *Ethereum) APIs() []rpc.API {

// Append any Sequencer APIs as enabled
if s.config.RollupSequencerEnableTxConditional {
// an effort to detect if running in a non-sequencer mode
if len(s.config.RollupSequencerHTTP) > 0 {
log.Warn("SendRawTransactionConditional enabled when RollupSequencerHTTP is defined. Skipping...")
} else {
apis = append(apis, sequencerapi.GetSendRawTxConditionalAPI(s.APIBackend))
}
apis = append(apis, sequencerapi.GetSendRawTxConditionalAPI(s.APIBackend, s.seqRPCService))
}

// Append all the local APIs and return
Expand Down
33 changes: 20 additions & 13 deletions internal/sequencerapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ var (
)

type sendRawTxCond struct {
b ethapi.Backend
b ethapi.Backend
seqRPC *rpc.Client
}

func GetSendRawTxConditionalAPI(b ethapi.Backend) rpc.API {
func GetSendRawTxConditionalAPI(b ethapi.Backend, seqRPC *rpc.Client) rpc.API {
return rpc.API{
Namespace: "eth",
Service: &sendRawTxCond{b},
Service: &sendRawTxCond{b, seqRPC},
}
}

Expand Down Expand Up @@ -75,15 +76,21 @@ func (s *sendRawTxCond) SendRawTransactionConditional(ctx context.Context, txByt
}
}

tx := new(types.Transaction)
if err := tx.UnmarshalBinary(txBytes); err != nil {
return common.Hash{}, err
}

// Set internal fields
tx.SetTime(time.Now())
tx.SetConditional(&cond)
sendRawTxConditionalAcceptedCounter.Inc(1)
// forward if seqRPC is set, otherwise submit the tx
if s.seqRPC != nil {
var hash common.Hash
err := s.seqRPC.CallContext(ctx, &hash, "eth_sendRawTransactionConditional", txBytes, cond)
return hash, err
} else {
tx := new(types.Transaction)
if err := tx.UnmarshalBinary(txBytes); err != nil {
return common.Hash{}, err
}

return ethapi.SubmitTransaction(ctx, s.b, tx)
// Set out-of-consensus internal tx fields
tx.SetTime(time.Now())
tx.SetConditional(&cond)
sendRawTxConditionalAcceptedCounter.Inc(1)
return ethapi.SubmitTransaction(ctx, s.b, tx)
}
}

0 comments on commit eec006a

Please sign in to comment.