Skip to content
Draft
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: 5 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func GetAPIs(apiBackend ethapi.Backend) []rpc.API {
Version: "1.0",
Service: ethapi.NewPublicSccApi(apiBackend),
Public: true,
}, {
Namespace: "sonic",
Version: "1.0",
Service: ethapi.NewPublicBundleAPI(apiBackend),
Public: true,
},
}
}
27 changes: 21 additions & 6 deletions api/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ func (diff *StateOverride) HasCodesExceedingOnChainLimit() bool {
return false
}

func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error) {
func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, timeout time.Duration, globalGasCap uint64, preArgs []TransactionArgs) (*core.ExecutionResult, error) {
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())

state, block, err := b.StateAndBlockByNumberOrHash(ctx, blockNrOrHash)
Expand Down Expand Up @@ -1169,8 +1169,23 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
evmcore.ProcessParentBlockHash(block.ParentHash, evm, state)
}

// Execute the message.
// Add sufficient gas to the pool.
gp := new(core.GasPool).AddGas(math.MaxUint64)

// Apply previous transactions if required.
for _, arg := range preArgs {
preMsg, err := arg.ToMessage(globalGasCap, block.BaseFee, log.Root())
if err != nil {
log.Error("failed to convert to message", "tx", arg.toTransaction().Hash(), "err", err)
continue
}
if _, err := core.ApplyMessage(evm, preMsg, gp); err != nil {
log.Error("failed to apply previous transaction", "tx", arg.toTransaction().Hash(), "err", err)
}
state.EndTransaction()
}

// Execute the message.
result, err := core.ApplyMessage(evm, msg, gp)
if err := vmError(); err != nil {
return nil, err
Expand Down Expand Up @@ -1223,7 +1238,7 @@ func (e *revertError) ErrorData() interface{} {
// Note, this function doesn't make and changes in the state/blockchain and is
// useful to execute and retrieve values.
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, stateOverrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) {
result, err := DoCall(ctx, s.b, args, blockNrOrHash, stateOverrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
result, err := DoCall(ctx, s.b, args, blockNrOrHash, stateOverrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap(), nil)
if err != nil {
return nil, err
}
Expand All @@ -1235,7 +1250,7 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, bl
}

// DoEstimateGas - binary search the gas requirement, as it may be higher than the amount used
func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, gasCap uint64) (hexutil.Uint64, error) {
func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, gasCap uint64, preArgs []TransactionArgs) (hexutil.Uint64, error) {
// Binary search the gas requirement, as it may be higher than the amount used
var (
lo uint64 = params.TxGas - 1
Expand Down Expand Up @@ -1313,7 +1328,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
executable := func(gas uint64) (bool, *core.ExecutionResult, error) {
args.Gas = (*hexutil.Uint64)(&gas)

result, err := DoCall(ctx, b, args, blockNrOrHash, overrides, blockOverrides, 0, gasCap)
result, err := DoCall(ctx, b, args, blockNrOrHash, overrides, blockOverrides, 0, gasCap, preArgs)
if err != nil {
if errors.Is(err, core.ErrIntrinsicGas) ||
errors.Is(err, core.ErrFloorDataGas) {
Expand Down Expand Up @@ -1445,7 +1460,7 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args TransactionA
if blockNrOrHash != nil {
bNrOrHash = *blockNrOrHash
}
return DoEstimateGas(ctx, s.b, args, bNrOrHash, overrides, blockOverrides, s.b.RPCGasCap())
return DoEstimateGas(ctx, s.b, args, bNrOrHash, overrides, blockOverrides, s.b.RPCGasCap(), nil)
}

// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
Expand Down
2 changes: 1 addition & 1 deletion api/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ func TestAPI_EIP2935_InvokesHistoryStorageContract(t *testing.T) {
timeout := time.Duration(time.Second)
gasCap := uint64(10000000)

result, err := DoCall(t.Context(), backend, txArgs, blockNrOrHash, stateOverrides, blockOverrides, timeout, gasCap)
result, err := DoCall(t.Context(), backend, txArgs, blockNrOrHash, stateOverrides, blockOverrides, timeout, gasCap, nil)
require.NoError(t, err)
require.False(t, result.Failed())
}
Expand Down
4 changes: 4 additions & 0 deletions api/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/rpc"

"github.com/0xsoniclabs/sonic/evmcore"
"github.com/0xsoniclabs/sonic/gossip/blockproc/bundle"
"github.com/0xsoniclabs/sonic/inter"
"github.com/0xsoniclabs/sonic/inter/iblockproc"
"github.com/0xsoniclabs/sonic/inter/state"
Expand Down Expand Up @@ -91,6 +92,9 @@ type Backend interface {
TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions)
SubscribeNewTxsNotify(chan<- evmcore.NewTxsNotify) notify.Subscription

// Bundle API
GetBundleExecutionInfo(common.Hash) *bundle.ExecutionInfo

ChainConfig(blockHeight idx.Block) *params.ChainConfig
ChainID() *big.Int
CurrentBlock() *evmcore.EvmBlock
Expand Down
53 changes: 41 additions & 12 deletions api/ethapi/backend_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading