mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
adds AddTransactions, AddBundle, AddBundles to the builder API
This commit is contained in:
parent
d20d30c753
commit
80ec7dcf02
7 changed files with 355 additions and 16 deletions
131
miner/builder.go
131
miner/builder.go
|
|
@ -22,6 +22,13 @@ import (
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrInvalidInclusionRange = errors.New("invalid inclusion range")
|
||||||
|
ErrInvalidBlockNumber = errors.New("invalid block number")
|
||||||
|
ErrExceedsMaxBlock = errors.New("block number exceeds max block")
|
||||||
|
ErrEmptyTxs = errors.New("empty transactions")
|
||||||
|
)
|
||||||
|
|
||||||
type BuilderConfig struct {
|
type BuilderConfig struct {
|
||||||
ChainConfig *params.ChainConfig
|
ChainConfig *params.ChainConfig
|
||||||
Engine consensus.Engine
|
Engine consensus.Engine
|
||||||
|
|
@ -77,28 +84,100 @@ func NewBuilder(config *BuilderConfig, args *BuilderArgs) (*Builder, error) {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SBundle struct {
|
func (b *Builder) addTransaction(txn *types.Transaction, env *environment) (*suavextypes.SimulateTransactionResult, error) {
|
||||||
BlockNumber *big.Int `json:"blockNumber,omitempty"` // if BlockNumber is set it must match DecryptionCondition!
|
|
||||||
MaxBlock *big.Int `json:"maxBlock,omitempty"`
|
|
||||||
Txs types.Transactions `json:"txs"`
|
|
||||||
RevertingHashes []common.Hash `json:"revertingHashes,omitempty"`
|
|
||||||
RefundPercent *int `json:"percent,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Builder) AddTransaction(txn *types.Transaction) (*suavextypes.SimulateTransactionResult, error) {
|
|
||||||
// If the context is not set, the logs will not be recorded
|
// If the context is not set, the logs will not be recorded
|
||||||
b.env.state.SetTxContext(txn.Hash(), b.env.tcount)
|
b.env.state.SetTxContext(txn.Hash(), b.env.tcount)
|
||||||
|
|
||||||
logs, err := b.wrk.commitTransaction(b.env, txn)
|
logs, err := b.wrk.commitTransaction(env, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &suavextypes.SimulateTransactionResult{
|
return &suavextypes.SimulateTransactionResult{
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
Success: false,
|
Success: false,
|
||||||
}, nil
|
}, err
|
||||||
}
|
}
|
||||||
return receiptToSimResult(&types.Receipt{Logs: logs}), nil
|
return receiptToSimResult(&types.Receipt{Logs: logs}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Builder) AddTransaction(txn *types.Transaction) (*suavextypes.SimulateTransactionResult, error) {
|
||||||
|
res, _ := b.addTransaction(txn, b.env)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Builder) AddTransactions(txns types.Transactions) ([]*suavextypes.SimulateTransactionResult, error) {
|
||||||
|
var result []*suavextypes.SimulateTransactionResult
|
||||||
|
snap := b.env.copy()
|
||||||
|
|
||||||
|
for _, txn := range txns {
|
||||||
|
res, err := b.addTransaction(txn, snap)
|
||||||
|
result = append(result, res)
|
||||||
|
if err != nil {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.env = snap
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Builder) addBundle(bundle *suavextypes.Bundle, env *environment) (*suavextypes.SimulateBundleResult, error) {
|
||||||
|
if err := checkBundleInclusion(b.env.header.Number, bundle); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
revertingHashes := bundle.RevertingHashesMap()
|
||||||
|
|
||||||
|
var results []*suavextypes.SimulateTransactionResult
|
||||||
|
for _, txn := range bundle.Txs {
|
||||||
|
result, err := b.addTransaction(txn, env)
|
||||||
|
results = append(results, result)
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := revertingHashes[txn.Hash()]; ok {
|
||||||
|
// continue if the transaction is in the reverting hashes
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return &suavextypes.SimulateBundleResult{
|
||||||
|
Error: err.Error(),
|
||||||
|
Success: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &suavextypes.SimulateBundleResult{
|
||||||
|
SimulateTransactionResults: results,
|
||||||
|
Success: true,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Builder) AddBundle(bundle *suavextypes.Bundle) (*suavextypes.SimulateBundleResult, error) {
|
||||||
|
snap := b.env.copy()
|
||||||
|
result, err := b.addBundle(bundle, snap)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return &suavextypes.SimulateBundleResult{
|
||||||
|
Error: err.Error(),
|
||||||
|
Success: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
b.env = snap
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Builder) AddBundles(bundles []*suavextypes.Bundle) ([]*suavextypes.SimulateBundleResult, error) {
|
||||||
|
var results []*suavextypes.SimulateBundleResult
|
||||||
|
snap := b.env.copy()
|
||||||
|
|
||||||
|
for _, bundle := range bundles {
|
||||||
|
result, err := b.addBundle(bundle, snap)
|
||||||
|
results = append(results, result)
|
||||||
|
if err != nil {
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.env = snap
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Builder) FillPending() error {
|
func (b *Builder) FillPending() error {
|
||||||
if err := b.wrk.commitPendingTxs(b.env); err != nil {
|
if err := b.wrk.commitPendingTxs(b.env); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -223,3 +302,33 @@ func executableDataToDenebExecutionPayload(data *engine.ExecutableData) (*deneb.
|
||||||
Withdrawals: withdrawalData,
|
Withdrawals: withdrawalData,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkBundleInclusion(currentBlockNumber *big.Int, bundle *suavextypes.Bundle) error {
|
||||||
|
if bundle.BlockNumber != nil && bundle.MaxBlock != nil && bundle.BlockNumber.Cmp(bundle.MaxBlock) > 0 {
|
||||||
|
return ErrInvalidInclusionRange
|
||||||
|
}
|
||||||
|
|
||||||
|
// check inclusion target if BlockNumber is set
|
||||||
|
if bundle.BlockNumber != nil {
|
||||||
|
if bundle.MaxBlock == nil && currentBlockNumber.Cmp(bundle.BlockNumber) != 0 {
|
||||||
|
return ErrInvalidBlockNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
if bundle.MaxBlock != nil {
|
||||||
|
if currentBlockNumber.Cmp(bundle.MaxBlock) > 0 {
|
||||||
|
return ErrExceedsMaxBlock
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentBlockNumber.Cmp(bundle.BlockNumber) < 0 {
|
||||||
|
return ErrInvalidBlockNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the bundle has transactions
|
||||||
|
if bundle.Txs == nil || bundle.Txs.Len() == 0 {
|
||||||
|
return ErrEmptyTxs
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/clique"
|
"github.com/ethereum/go-ethereum/consensus/clique"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
suavextypes "github.com/ethereum/go-ethereum/suave/builder/api"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -40,6 +43,110 @@ func TestBuilder_AddTxn_Simple(t *testing.T) {
|
||||||
require.Len(t, builder.env.receipts, 1)
|
require.Len(t, builder.env.receipts, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuilder_AddTxns_Simple(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
config, backend := newMockBuilderConfig(t)
|
||||||
|
builder, err := NewBuilder(config, &BuilderArgs{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx1 := backend.newRandomTx(false)
|
||||||
|
tx2 := backend.newRandomTxWithNonce(1)
|
||||||
|
|
||||||
|
res, err := builder.AddTransactions([]*types.Transaction{tx1, tx2})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, res, 2)
|
||||||
|
for _, r := range res {
|
||||||
|
require.True(t, r.Success)
|
||||||
|
}
|
||||||
|
|
||||||
|
tx3 := backend.newRandomTxWithNonce(2)
|
||||||
|
tx4 := backend.newRandomTxWithNonce(1000) // fails with nonce too high
|
||||||
|
|
||||||
|
res, err = builder.AddTransactions([]*types.Transaction{tx3, tx4})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, res, 2)
|
||||||
|
require.True(t, res[0].Success)
|
||||||
|
require.False(t, res[1].Success)
|
||||||
|
require.Len(t, builder.env.txs, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuilder_AddBundle_Simple(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
config, backend := newMockBuilderConfig(t)
|
||||||
|
builder, err := NewBuilder(config, &BuilderArgs{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx1 := backend.newRandomTx(false)
|
||||||
|
tx2 := backend.newRandomTxWithNonce(1)
|
||||||
|
|
||||||
|
bundle := &suavextypes.Bundle{
|
||||||
|
Txs: []*types.Transaction{tx1, tx2},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := builder.AddBundle(bundle)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, res.Success)
|
||||||
|
require.Len(t, res.SimulateTransactionResults, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuilder_AddBundle_RevertHashes(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
config, backend := newMockBuilderConfig(t)
|
||||||
|
builder, err := NewBuilder(config, &BuilderArgs{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx1 := backend.newRandomTx(false)
|
||||||
|
tx2 := backend.newRandomTxWithNonce(3) // fails with nonce too high
|
||||||
|
|
||||||
|
bundle := &suavextypes.Bundle{
|
||||||
|
Txs: []*types.Transaction{tx1, tx2},
|
||||||
|
RevertingHashes: []common.Hash{tx2.Hash()},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := builder.AddBundle(bundle)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, res.Success)
|
||||||
|
require.Len(t, res.SimulateTransactionResults, 2)
|
||||||
|
require.True(t, res.SimulateTransactionResults[0].Success)
|
||||||
|
require.False(t, res.SimulateTransactionResults[1].Success)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuilder_AddBundle_InvalidInclusion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
config, backend := newMockBuilderConfig(t)
|
||||||
|
builder, err := NewBuilder(config, &BuilderArgs{
|
||||||
|
Slot: 10,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx1 := backend.newRandomTx(false)
|
||||||
|
tx2 := backend.newRandomTx(false)
|
||||||
|
|
||||||
|
bundle := &suavextypes.Bundle{
|
||||||
|
Txs: []*types.Transaction{tx1, tx2},
|
||||||
|
BlockNumber: big.NewInt(20),
|
||||||
|
}
|
||||||
|
|
||||||
|
backend.insertRandomBlocks(10)
|
||||||
|
require.Equal(t, uint64(10), backend.chain.CurrentBlock().Number.Uint64())
|
||||||
|
|
||||||
|
res, err := builder.AddBundle(bundle)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, res.Success)
|
||||||
|
require.Len(t, res.SimulateTransactionResults, 0)
|
||||||
|
|
||||||
|
bundle = &suavextypes.Bundle{
|
||||||
|
Txs: []*types.Transaction{tx1, tx2},
|
||||||
|
BlockNumber: big.NewInt(5),
|
||||||
|
MaxBlock: big.NewInt(6),
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = builder.AddBundle(bundle)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, res.Success)
|
||||||
|
require.Len(t, res.SimulateTransactionResults, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuilder_FillTransactions(t *testing.T) {
|
func TestBuilder_FillTransactions(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
config, backend := newMockBuilderConfig(t)
|
config, backend := newMockBuilderConfig(t)
|
||||||
|
|
@ -118,10 +225,8 @@ func TestBuilder_Bid(t *testing.T) {
|
||||||
_, err = builder.BuildBlock()
|
_, err = builder.BuildBlock()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
req, err := builder.Bid([48]byte{})
|
_, err = builder.Bid([48]byte{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fmt.Println("-- req --", req)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockBuilderConfig(t *testing.T) (*BuilderConfig, *testWorkerBackend) {
|
func newMockBuilderConfig(t *testing.T) (*BuilderConfig, *testWorkerBackend) {
|
||||||
|
|
@ -145,6 +250,49 @@ func newMockBuilderConfig(t *testing.T) (*BuilderConfig, *testWorkerBackend) {
|
||||||
return bConfig, backend
|
return bConfig, backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *testWorkerBackend) newRandomTxWithNonce(nonce uint64) *types.Transaction {
|
||||||
|
gasPrice := big.NewInt(10 * params.InitialBaseFee)
|
||||||
|
tx, _ := types.SignTx(types.NewTransaction(nonce, testUserAddress, big.NewInt(1000), params.TxGas, gasPrice, nil), types.HomesteadSigner{}, testBankKey)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *testWorkerBackend) insertRandomBlocks(n int) []*types.Block {
|
||||||
|
extraVanity := 32
|
||||||
|
extraSeal := crypto.SignatureLength
|
||||||
|
diffInTurn := big.NewInt(2)
|
||||||
|
signer := new(types.HomesteadSigner)
|
||||||
|
_, blocks, _ := core.GenerateChainWithGenesis(b.genesis, b.chain.Engine(), n, func(i int, block *core.BlockGen) {
|
||||||
|
block.SetDifficulty(big.NewInt(2)) // diffInTurn
|
||||||
|
|
||||||
|
if i != 1 {
|
||||||
|
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testBankAddress), common.Address{0x00}, new(big.Int), params.TxGas, block.BaseFee(), nil), signer, testBankKey)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
block.AddTxWithChain(b.chain, tx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, block := range blocks {
|
||||||
|
header := block.Header()
|
||||||
|
if i > 0 {
|
||||||
|
header.ParentHash = blocks[i-1].Hash()
|
||||||
|
}
|
||||||
|
header.Extra = make([]byte, extraVanity+extraSeal)
|
||||||
|
header.Difficulty = diffInTurn
|
||||||
|
|
||||||
|
sig, _ := crypto.Sign(clique.SealHash(header).Bytes(), testBankKey)
|
||||||
|
copy(header.Extra[len(header.Extra)-extraSeal:], sig)
|
||||||
|
blocks[i] = block.WithSeal(header)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := b.chain.InsertChain(blocks); err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to insert initial blocks: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks
|
||||||
|
}
|
||||||
|
|
||||||
func (b *testWorkerBackend) newCall(to common.Address, data []byte) *types.Transaction {
|
func (b *testWorkerBackend) newCall(to common.Address, data []byte) *types.Transaction {
|
||||||
gasPrice := big.NewInt(10 * params.InitialBaseFee)
|
gasPrice := big.NewInt(10 * params.InitialBaseFee)
|
||||||
tx, _ := types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), to, big.NewInt(0), 1000000, gasPrice, data), types.HomesteadSigner{}, testBankKey)
|
tx, _ := types.SignTx(types.NewTransaction(b.txPool.Nonce(testBankAddress), to, big.NewInt(0), 1000000, gasPrice, data), types.HomesteadSigner{}, testBankKey)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,14 @@ type Bundle struct {
|
||||||
RefundPercent *int `json:"percent,omitempty"`
|
RefundPercent *int `json:"percent,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bundle *Bundle) RevertingHashesMap() map[common.Hash]struct{} {
|
||||||
|
m := make(map[common.Hash]struct{})
|
||||||
|
for _, hash := range bundle.RevertingHashes {
|
||||||
|
m[hash] = struct{}{}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
type BuildBlockArgs struct {
|
type BuildBlockArgs struct {
|
||||||
Slot uint64 `json:"slot"`
|
Slot uint64 `json:"slot"`
|
||||||
ProposerPubkey []byte `json:"proposerPubkey"`
|
ProposerPubkey []byte `json:"proposerPubkey"`
|
||||||
|
|
@ -52,6 +60,12 @@ type SimulateTransactionResult struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SimulateBundleResult struct {
|
||||||
|
SimulateTransactionResults []*SimulateTransactionResult
|
||||||
|
Success bool
|
||||||
|
Error string
|
||||||
|
}
|
||||||
|
|
||||||
// field type overrides for gencodec
|
// field type overrides for gencodec
|
||||||
type simulateTransactionResultMarshaling struct {
|
type simulateTransactionResultMarshaling struct {
|
||||||
Egp hexutil.Uint64
|
Egp hexutil.Uint64
|
||||||
|
|
@ -77,6 +91,9 @@ type SubmitBlockRequest struct {
|
||||||
type API interface {
|
type API interface {
|
||||||
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
||||||
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||||
|
AddTransactions(ctx context.Context, sessionId string, txs types.Transactions) ([]*SimulateTransactionResult, error)
|
||||||
|
AddBundle(ctx context.Context, sessionId string, bundle *Bundle) (*SimulateBundleResult, error)
|
||||||
|
AddBundles(ctx context.Context, sessionId string, bundles []*Bundle) ([]*SimulateBundleResult, error)
|
||||||
BuildBlock(ctx context.Context, sessionId string) error
|
BuildBlock(ctx context.Context, sessionId string) error
|
||||||
Bid(ctx context.Context, sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
Bid(ctx context.Context, sessioId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,24 @@ func (a *APIClient) AddTransaction(ctx context.Context, sessionId string, tx *ty
|
||||||
return receipt, err
|
return receipt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *APIClient) AddTransactions(ctx context.Context, sessionId string, txs types.Transactions) ([]*SimulateTransactionResult, error) {
|
||||||
|
var receipt []*SimulateTransactionResult
|
||||||
|
err := a.rpc.CallContext(ctx, &receipt, "suavex_addTransactions", sessionId, txs)
|
||||||
|
return receipt, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIClient) AddBundle(ctx context.Context, sessionId string, bundle *Bundle) (*SimulateBundleResult, error) {
|
||||||
|
var receipt *SimulateBundleResult
|
||||||
|
err := a.rpc.CallContext(ctx, &receipt, "suavex_addBundle", sessionId, bundle)
|
||||||
|
return receipt, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIClient) AddBundles(ctx context.Context, sessionId string, bundles []*Bundle) ([]*SimulateBundleResult, error) {
|
||||||
|
var receipt []*SimulateBundleResult
|
||||||
|
err := a.rpc.CallContext(ctx, &receipt, "suavex_addBundles", sessionId, bundles)
|
||||||
|
return receipt, err
|
||||||
|
}
|
||||||
|
|
||||||
func (a *APIClient) BuildBlock(ctx context.Context, sessionId string) error {
|
func (a *APIClient) BuildBlock(ctx context.Context, sessionId string) error {
|
||||||
return a.rpc.CallContext(ctx, nil, "suavex_buildBlock", sessionId)
|
return a.rpc.CallContext(ctx, nil, "suavex_buildBlock", sessionId)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ var _ API = (*Server)(nil)
|
||||||
type SessionManager interface {
|
type SessionManager interface {
|
||||||
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
||||||
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||||
|
AddTransactions(sessionId string, txs types.Transactions) ([]*SimulateTransactionResult, error)
|
||||||
|
AddBundle(sessionId string, bundle *Bundle) (*SimulateBundleResult, error)
|
||||||
|
AddBundles(sessionId string, bundles []*Bundle) ([]*SimulateBundleResult, error)
|
||||||
BuildBlock(sessionId string) error
|
BuildBlock(sessionId string) error
|
||||||
Bid(sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
Bid(sessionId string, blsPubKey phase0.BLSPubKey) (*SubmitBlockRequest, error)
|
||||||
}
|
}
|
||||||
|
|
@ -36,6 +39,18 @@ func (s *Server) AddTransaction(ctx context.Context, sessionId string, tx *types
|
||||||
return s.sessionMngr.AddTransaction(sessionId, tx)
|
return s.sessionMngr.AddTransaction(sessionId, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) AddTransactions(ctx context.Context, sessionId string, txs types.Transactions) ([]*SimulateTransactionResult, error) {
|
||||||
|
return s.sessionMngr.AddTransactions(sessionId, txs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) AddBundle(ctx context.Context, sessionId string, bundle *Bundle) (*SimulateBundleResult, error) {
|
||||||
|
return s.sessionMngr.AddBundle(sessionId, bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) AddBundles(ctx context.Context, sessionId string, bundles []*Bundle) ([]*SimulateBundleResult, error) {
|
||||||
|
return s.sessionMngr.AddBundles(sessionId, bundles)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) BuildBlock(ctx context.Context, sessionId string) error {
|
func (s *Server) BuildBlock(ctx context.Context, sessionId string) error {
|
||||||
return s.sessionMngr.BuildBlock(sessionId)
|
return s.sessionMngr.BuildBlock(sessionId)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,16 @@ func (nullSessionManager) AddTransaction(sessionId string, tx *types.Transaction
|
||||||
return &SimulateTransactionResult{Logs: []*SimulatedLog{}}, nil
|
return &SimulateTransactionResult{Logs: []*SimulatedLog{}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nullSessionManager) AddBundle(sessionId string, bundle Bundle) error {
|
func (nullSessionManager) AddTransactions(sessionId string, txs types.Transactions) ([]*SimulateTransactionResult, error) {
|
||||||
return nil
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nullSessionManager) AddBundle(sessionId string, bundle *Bundle) (*SimulateBundleResult, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nullSessionManager) AddBundles(sessionId string, bundles []*Bundle) ([]*SimulateBundleResult, error) {
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nullSessionManager) BuildBlock(sessionId string) error {
|
func (nullSessionManager) BuildBlock(sessionId string) error {
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,30 @@ func (s *SessionManager) AddTransaction(sessionId string, tx *types.Transaction)
|
||||||
return builder.AddTransaction(tx)
|
return builder.AddTransaction(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SessionManager) AddTransactions(sessionId string, txs types.Transactions) ([]*api.SimulateTransactionResult, error) {
|
||||||
|
builder, err := s.getSession(sessionId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return builder.AddTransactions(txs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SessionManager) AddBundle(sessionId string, bundle *api.Bundle) (*api.SimulateBundleResult, error) {
|
||||||
|
builder, err := s.getSession(sessionId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return builder.AddBundle(bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SessionManager) AddBundles(sessionId string, bundles []*api.Bundle) ([]*api.SimulateBundleResult, error) {
|
||||||
|
builder, err := s.getSession(sessionId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return builder.AddBundles(bundles)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SessionManager) BuildBlock(sessionId string) error {
|
func (s *SessionManager) BuildBlock(sessionId string) error {
|
||||||
builder, err := s.getSession(sessionId)
|
builder, err := s.getSession(sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue