mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
More fixes
This commit is contained in:
parent
84f5a665b7
commit
1652002fad
10 changed files with 173 additions and 84 deletions
|
|
@ -2,51 +2,19 @@ package types
|
|||
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
type DataId [16]byte
|
||||
|
||||
// Structs
|
||||
|
||||
type BuildBlockArgs struct {
|
||||
Slot uint64
|
||||
ProposerPubkey []byte
|
||||
Parent common.Hash
|
||||
Timestamp uint64
|
||||
FeeRecipient common.Address
|
||||
GasLimit uint64
|
||||
Random common.Hash
|
||||
Withdrawals []*Withdrawal
|
||||
Slot uint64
|
||||
ProposerPubkey []byte
|
||||
Parent common.Hash
|
||||
Timestamp uint64
|
||||
FeeRecipient common.Address
|
||||
GasLimit uint64
|
||||
Random common.Hash
|
||||
Withdrawals []*Withdrawal
|
||||
ParentBeaconBlockRoot common.Hash
|
||||
Extra []byte
|
||||
BeaconRoot common.Hash
|
||||
FillPending bool
|
||||
}
|
||||
|
||||
type DataRecord struct {
|
||||
Id DataId
|
||||
Salt DataId
|
||||
DecryptionCondition uint64
|
||||
AllowedPeekers []common.Address
|
||||
AllowedStores []common.Address
|
||||
Version string
|
||||
}
|
||||
|
||||
type HttpRequest struct {
|
||||
Url string
|
||||
Method string
|
||||
Headers []string
|
||||
Body []byte
|
||||
WithFlashbotsSignature bool
|
||||
}
|
||||
|
||||
type SimulateTransactionResult struct {
|
||||
Egp uint64
|
||||
Logs []*SimulatedLog
|
||||
Success bool
|
||||
Error string
|
||||
}
|
||||
|
||||
type SimulatedLog struct {
|
||||
Data []byte
|
||||
Addr common.Address
|
||||
Topics []common.Hash
|
||||
Extra []byte
|
||||
BeaconRoot common.Hash
|
||||
FillPending bool
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
suavextypes "github.com/ethereum/go-ethereum/suave/builder/api"
|
||||
"github.com/flashbots/go-boost-utils/ssz"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
|
@ -84,13 +85,13 @@ type SBundle struct {
|
|||
RefundPercent *int `json:"percent,omitempty"`
|
||||
}
|
||||
|
||||
func (b *Builder) AddTransaction(txn *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
func (b *Builder) AddTransaction(txn *types.Transaction) (*suavextypes.SimulateTransactionResult, error) {
|
||||
// If the context is not set, the logs will not be recorded
|
||||
b.env.state.SetTxContext(txn.Hash(), b.env.tcount)
|
||||
|
||||
logs, err := b.wrk.commitTransaction(b.env, txn)
|
||||
if err != nil {
|
||||
return &types.SimulateTransactionResult{
|
||||
return &suavextypes.SimulateTransactionResult{
|
||||
Error: err.Error(),
|
||||
Success: false,
|
||||
}, nil
|
||||
|
|
@ -175,13 +176,13 @@ type SubmitBlockRequest struct {
|
|||
Root phase0.Root
|
||||
}
|
||||
|
||||
func receiptToSimResult(receipt *types.Receipt) *types.SimulateTransactionResult {
|
||||
result := &types.SimulateTransactionResult{
|
||||
func receiptToSimResult(receipt *types.Receipt) *suavextypes.SimulateTransactionResult {
|
||||
result := &suavextypes.SimulateTransactionResult{
|
||||
Success: true,
|
||||
Logs: []*types.SimulatedLog{},
|
||||
Logs: []*suavextypes.SimulatedLog{},
|
||||
}
|
||||
for _, log := range receipt.Logs {
|
||||
result.Logs = append(result.Logs, &types.SimulatedLog{
|
||||
result.Logs = append(result.Logs, &suavextypes.SimulatedLog{
|
||||
Addr: log.Address,
|
||||
Topics: log.Topics,
|
||||
Data: log.Data,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
// TODO: Can we aggregate all the gencodec generation into a single file?
|
||||
//go:generate go run github.com/fjl/gencodec -type BuildBlockArgs -field-override buildBlockArgsMarshaling -out gen_buildblockargs_json.go
|
||||
//go:generate go run github.com/fjl/gencodec -type SimulateTransactionResult -field-override simulateTransactionResultMarshaling -out gen_simulatetxnresult_json.go
|
||||
//go:generate go run github.com/fjl/gencodec -type SimulatedLog -field-override simulateLogMarshaling -out gen_simulateLog_json.go
|
||||
|
||||
type Bundle struct {
|
||||
BlockNumber *big.Int `json:"blockNumber,omitempty"` // if BlockNumber is set it must match DecryptionCondition!
|
||||
|
|
@ -40,8 +43,31 @@ type buildBlockArgsMarshaling struct {
|
|||
Extra hexutil.Bytes
|
||||
}
|
||||
|
||||
type SimulateTransactionResult struct {
|
||||
Egp uint64 `json:"egp"`
|
||||
Logs []*SimulatedLog `json:"logs"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// field type overrides for gencodec
|
||||
type simulateTransactionResultMarshaling struct {
|
||||
Egp hexutil.Uint64
|
||||
}
|
||||
|
||||
type SimulatedLog struct {
|
||||
Data []byte `json:"data"`
|
||||
Addr common.Address `json:"addr"`
|
||||
Topics []common.Hash `json:"topics"`
|
||||
}
|
||||
|
||||
type simulateLogMarshaling struct {
|
||||
Data hexutil.Bytes
|
||||
}
|
||||
|
||||
type API interface {
|
||||
NewSession(ctx context.Context, args *BuildBlockArgs) (string, error)
|
||||
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error)
|
||||
AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||
BuildBlock(ctx context.Context, sessionId string) error
|
||||
Bid(ctx context.Context, sessioId string, blsPubKey string) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ func (a *APIClient) NewSession(ctx context.Context, args *BuildBlockArgs) (strin
|
|||
return id, err
|
||||
}
|
||||
|
||||
func (a *APIClient) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
var receipt *types.SimulateTransactionResult
|
||||
func (a *APIClient) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error) {
|
||||
var receipt *SimulateTransactionResult
|
||||
err := a.rpc.CallContext(ctx, &receipt, "suavex_addTransaction", sessionId, tx)
|
||||
return receipt, err
|
||||
}
|
||||
|
|
@ -44,3 +44,7 @@ func (a *APIClient) AddTransaction(ctx context.Context, sessionId string, tx *ty
|
|||
func (a *APIClient) BuildBlock(ctx context.Context, sessionId string) error {
|
||||
return a.rpc.CallContext(ctx, nil, "suavex_buildBlock", sessionId)
|
||||
}
|
||||
|
||||
func (a *APIClient) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
||||
return a.rpc.CallContext(ctx, nil, "suavex_bid", sessioId, blsPubKey)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
var _ API = (*Server)(nil)
|
||||
|
||||
// SessionManager is the backend that manages the session state of the builder API.
|
||||
type SessionManager interface {
|
||||
NewSession(context.Context, *BuildBlockArgs) (string, error)
|
||||
AddTransaction(sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error)
|
||||
AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error)
|
||||
BuildBlock(sessionId string) error
|
||||
Bid(sessionId string, blsPubKey string) error
|
||||
}
|
||||
|
||||
func NewServer(s SessionManager) *Server {
|
||||
|
|
@ -28,7 +31,7 @@ func (s *Server) NewSession(ctx context.Context, args *BuildBlockArgs) (string,
|
|||
return s.sessionMngr.NewSession(ctx, args)
|
||||
}
|
||||
|
||||
func (s *Server) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
func (s *Server) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error) {
|
||||
return s.sessionMngr.AddTransaction(sessionId, tx)
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +39,11 @@ func (s *Server) BuildBlock(ctx context.Context, sessionId string) error {
|
|||
return s.sessionMngr.BuildBlock(sessionId)
|
||||
}
|
||||
|
||||
func (s *Server) Bid(ctx context.Context, sessioId string, blsPubKey string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
type MockServer struct {
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +51,8 @@ func (s *MockServer) NewSession(ctx context.Context, args *BuildBlockArgs) (stri
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func (s *MockServer) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
return &types.SimulateTransactionResult{}, nil
|
||||
func (s *MockServer) AddTransaction(ctx context.Context, sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error) {
|
||||
return &SimulateTransactionResult{}, nil
|
||||
}
|
||||
|
||||
func (s *MockServer) BuildBlock(ctx context.Context) error {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ func (nullSessionManager) NewSession(ctx context.Context, args *BuildBlockArgs)
|
|||
return "1", ctx.Err()
|
||||
}
|
||||
|
||||
func (nullSessionManager) AddTransaction(sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
return &types.SimulateTransactionResult{Logs: []*types.SimulatedLog{}}, nil
|
||||
func (nullSessionManager) AddTransaction(sessionId string, tx *types.Transaction) (*SimulateTransactionResult, error) {
|
||||
return &SimulateTransactionResult{Logs: []*SimulatedLog{}}, nil
|
||||
}
|
||||
|
||||
func (nullSessionManager) AddBundle(sessionId string, bundle Bundle) error {
|
||||
|
|
@ -45,3 +45,7 @@ func (nullSessionManager) AddBundle(sessionId string, bundle Bundle) error {
|
|||
func (nullSessionManager) BuildBlock(sessionId string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nullSessionManager) Bid(sessioId string, blsPubKey string) error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
49
suave/builder/api/gen_simulateLog_json.go
Normal file
49
suave/builder/api/gen_simulateLog_json.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
var _ = (*simulateLogMarshaling)(nil)
|
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (s SimulatedLog) MarshalJSON() ([]byte, error) {
|
||||
type SimulatedLog struct {
|
||||
Data hexutil.Bytes `json:"data"`
|
||||
Addr common.Address `json:"addr"`
|
||||
Topics []common.Hash `json:"topics"`
|
||||
}
|
||||
var enc SimulatedLog
|
||||
enc.Data = s.Data
|
||||
enc.Addr = s.Addr
|
||||
enc.Topics = s.Topics
|
||||
return json.Marshal(&enc)
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (s *SimulatedLog) UnmarshalJSON(input []byte) error {
|
||||
type SimulatedLog struct {
|
||||
Data *hexutil.Bytes `json:"data"`
|
||||
Addr *common.Address `json:"addr"`
|
||||
Topics []common.Hash `json:"topics"`
|
||||
}
|
||||
var dec SimulatedLog
|
||||
if err := json.Unmarshal(input, &dec); err != nil {
|
||||
return err
|
||||
}
|
||||
if dec.Data != nil {
|
||||
s.Data = *dec.Data
|
||||
}
|
||||
if dec.Addr != nil {
|
||||
s.Addr = *dec.Addr
|
||||
}
|
||||
if dec.Topics != nil {
|
||||
s.Topics = dec.Topics
|
||||
}
|
||||
return nil
|
||||
}
|
||||
54
suave/builder/api/gen_simulatetxnresult_json.go
Normal file
54
suave/builder/api/gen_simulatetxnresult_json.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
var _ = (*simulateTransactionResultMarshaling)(nil)
|
||||
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (s SimulateTransactionResult) MarshalJSON() ([]byte, error) {
|
||||
type SimulateTransactionResult struct {
|
||||
Egp hexutil.Uint64 `json:"egp"`
|
||||
Logs []*SimulatedLog `json:"logs"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
var enc SimulateTransactionResult
|
||||
enc.Egp = hexutil.Uint64(s.Egp)
|
||||
enc.Logs = s.Logs
|
||||
enc.Success = s.Success
|
||||
enc.Error = s.Error
|
||||
return json.Marshal(&enc)
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (s *SimulateTransactionResult) UnmarshalJSON(input []byte) error {
|
||||
type SimulateTransactionResult struct {
|
||||
Egp *hexutil.Uint64 `json:"egp"`
|
||||
Logs []*SimulatedLog `json:"logs"`
|
||||
Success *bool `json:"success"`
|
||||
Error *string `json:"error"`
|
||||
}
|
||||
var dec SimulateTransactionResult
|
||||
if err := json.Unmarshal(input, &dec); err != nil {
|
||||
return err
|
||||
}
|
||||
if dec.Egp != nil {
|
||||
s.Egp = uint64(*dec.Egp)
|
||||
}
|
||||
if dec.Logs != nil {
|
||||
s.Logs = dec.Logs
|
||||
}
|
||||
if dec.Success != nil {
|
||||
s.Success = *dec.Success
|
||||
}
|
||||
if dec.Error != nil {
|
||||
s.Error = *dec.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ func (s *SessionManager) getSession(sessionId string) (*miner.Builder, error) {
|
|||
return session, nil
|
||||
}
|
||||
|
||||
func (s *SessionManager) AddTransaction(sessionId string, tx *types.Transaction) (*types.SimulateTransactionResult, error) {
|
||||
func (s *SessionManager) AddTransaction(sessionId string, tx *types.Transaction) (*api.SimulateTransactionResult, error) {
|
||||
builder, err := s.getSession(sessionId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -13,31 +13,6 @@ import (
|
|||
var AllowedPeekerAny = common.HexToAddress("0xC8df3686b4Afb2BB53e60EAe97EF043FE03Fb829") // "*"
|
||||
|
||||
type Bytes = hexutil.Bytes
|
||||
type DataId = types.DataId
|
||||
|
||||
type DataRecord struct {
|
||||
Id types.DataId
|
||||
Salt types.DataId
|
||||
DecryptionCondition uint64
|
||||
AllowedPeekers []common.Address
|
||||
AllowedStores []common.Address
|
||||
Version string
|
||||
CreationTx *types.Transaction
|
||||
Signature []byte
|
||||
}
|
||||
|
||||
func (b *DataRecord) ToInnerRecord() types.DataRecord {
|
||||
return types.DataRecord{
|
||||
Id: b.Id,
|
||||
Salt: b.Salt,
|
||||
DecryptionCondition: b.DecryptionCondition,
|
||||
AllowedPeekers: b.AllowedPeekers,
|
||||
AllowedStores: b.AllowedStores,
|
||||
Version: b.Version,
|
||||
}
|
||||
}
|
||||
|
||||
type MEVMBid = types.DataRecord
|
||||
|
||||
type BuildBlockArgs = types.BuildBlockArgs
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue