Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
- --log-tags={{ .Values.config.logTags }}
{{- end }}
- --keystore-dir={{ .Values.keystore.dir }}
- --simulation-url={{ .Values.config.simulationUrl }}
- --keystore-password=$(KEYSTORE_PASSWORD)
- --l1-rpc-urls={{ .Values.config.l1RpcUrls | join "," }}
- --settlement-rpc-url={{ .Values.config.settlementRpcUrl }}
Expand Down
1 change: 1 addition & 0 deletions infrastructure/charts/mev-commit-preconf-rpc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ config:
httpPort: 8080
logLevel: "info"
logFormat: "json"
simulationUrl: http://1.2.3.4
logTags: ""
l1RpcUrls:
- ""
Expand Down
2 changes: 1 addition & 1 deletion p2p/gen/openapi/debugapi/v1/debugapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ definitions:
`NullValue` is a singleton enumeration to represent the null value for the
`Value` type union.

The JSON representation for `NullValue` is JSON `null`.
The JSON representation for `NullValue` is JSON `null`.
v1CancelTransactionResponse:
type: object
example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ definitions:
`NullValue` is a singleton enumeration to represent the null value for the
`Value` type union.

The JSON representation for `NullValue` is JSON `null`.
The JSON representation for `NullValue` is JSON `null`.
v1Notification:
type: object
properties:
Expand Down
11 changes: 6 additions & 5 deletions p2p/pkg/rpc/provider/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@ func TestShutterisedBidOptionsProcessing(t *testing.T) {
var bidOptionsBytes []byte
var err error

if tc.name == "mixed bid options" {
switch tc.name {
case "mixed bid options":
// Mixed options with position constraint and shutterised option
bidderOpts = &bidderapiv1.BidOptions{
Options: []*bidderapiv1.BidOption{
Expand All @@ -948,7 +949,7 @@ func TestShutterisedBidOptionsProcessing(t *testing.T) {
},
},
}
} else if tc.name == "multiple shutterised bid options" {
case "multiple shutterised bid options":
// Multiple shutterised options - parse comma-separated values
identityPrefixes := strings.Split(tc.identityPrefix, ",")
encryptedTxs := strings.Split(tc.encryptedTx, ",")
Expand All @@ -973,13 +974,13 @@ func TestShutterisedBidOptionsProcessing(t *testing.T) {
},
},
}
} else if tc.name == "invalid bid options marshaling" {
case "invalid bid options marshaling":
// Invalid protobuf data
bidOptionsBytes = []byte("invalid protobuf data")
} else if tc.name == "nil shutterised bid option" {
case "nil shutterised bid option":
// Nil bid options for nil case
bidderOpts = nil
} else {
default:
// Single valid shutterised option
bidderOpts = &bidderapiv1.BidOptions{
Options: []*bidderapiv1.BidOption{
Expand Down
33 changes: 30 additions & 3 deletions tools/preconf-rpc/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
bridgeLimitWei = 1000000000000000000 // 1 ETH
)

type positionConstraintKey struct{}

type Bidder interface {
Estimate() (int64, error)
}
Expand All @@ -32,6 +34,7 @@ type Store interface {
GetTransactionByHash(ctx context.Context, txnHash common.Hash) (*sender.Transaction, error)
GetTransactionsForBlock(ctx context.Context, blockNumber int64) ([]*sender.Transaction, error)
GetTransactionCommitments(ctx context.Context, txnHash common.Hash) ([]*bidderapiv1.Commitment, error)
GetTransactionLogs(ctx context.Context, txnHash common.Hash) ([]*types.Log, error)
GetBalance(ctx context.Context, account common.Address) (*big.Int, error)
GetCurrentNonce(ctx context.Context, account common.Address) uint64
}
Expand All @@ -45,6 +48,15 @@ type Sender interface {
CancelTransaction(ctx context.Context, txHash common.Hash) (bool, error)
}

func SetPositionConstraint(ctx context.Context, constraint *bidderapiv1.PositionConstraint) context.Context {
return context.WithValue(ctx, positionConstraintKey{}, constraint)
}

func getPositionConstraint(ctx context.Context) (*bidderapiv1.PositionConstraint, bool) {
value, ok := ctx.Value(positionConstraintKey{}).(*bidderapiv1.PositionConstraint)
return value, ok
}

type rpcMethodHandler struct {
logger *slog.Logger
pricer Pricer
Expand Down Expand Up @@ -356,12 +368,18 @@ func (h *rpcMethodHandler) handleSendRawTx(
}
}

err = h.sndr.Enqueue(ctx, &sender.Transaction{
txnToEnqueue := &sender.Transaction{
Transaction: txn,
Raw: rawTxHex,
Sender: txSender,
Type: txType,
})
}
constraint, ok := getPositionConstraint(ctx)
if ok {
txnToEnqueue.Constraint = constraint
}

err = h.sndr.Enqueue(ctx, txnToEnqueue)
if err != nil {
h.logger.Error("Failed to enqueue transaction for sending", "error", err, "sender", txSender.Hex())
return nil, false, rpcserver.NewJSONErr(
Expand Down Expand Up @@ -415,6 +433,15 @@ func (h *rpcMethodHandler) handleGetTxReceipt(ctx context.Context, params ...any
return nil, true, nil
}

logs, err := h.store.GetTransactionLogs(ctx, txHash)
if err != nil {
h.logger.Error("Failed to get transaction logs", "error", err, "txHash", txHash)
return nil, false, rpcserver.NewJSONErr(
rpcserver.CodeCustomError,
"failed to get transaction logs",
)
}

result := map[string]interface{}{
"type": hexutil.Uint(txn.Transaction.Type()),
"transactionHash": txn.Hash().Hex(),
Expand All @@ -424,7 +451,7 @@ func (h *rpcMethodHandler) handleGetTxReceipt(ctx context.Context, params ...any
"contractAddress": (common.Address{}).Hex(),
"gasUsed": hexutil.Uint64(0),
"cumulativeGasUsed": hexutil.Uint64(1),
"logs": []*types.Log{}, // should be [] not null
"logs": logs,
"logsBloom": hexutil.Bytes(types.Bloom{}.Bytes()),
"effectiveGasPrice": hexutil.EncodeBig(big.NewInt(0)),
}
Expand Down
9 changes: 9 additions & 0 deletions tools/preconf-rpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ var (
Value: "",
}

optionSimulationURL = &cli.StringFlag{
Name: "simulation-url",
Usage: "URL for the transaction simulation service",
EnvVars: []string{"PRECONF_RPC_SIMULATION_URL"},
Required: true,
}

optionLogFmt = &cli.StringFlag{
Name: "log-fmt",
Usage: "log format to use, options are 'text' or 'json'",
Expand Down Expand Up @@ -285,6 +292,7 @@ func main() {
optionBidderThreshold,
optionBidderTopup,
optionAuthToken,
optionSimulationURL,
},
Action: func(c *cli.Context) error {
logger, err := util.NewLogger(
Expand Down Expand Up @@ -370,6 +378,7 @@ func main() {
PricerAPIKey: c.String(optionBlocknativeAPIKey.Name),
Webhooks: c.StringSlice(optionWebhookURLs.Name),
Token: c.String(optionAuthToken.Name),
SimulatorURL: c.String(optionSimulationURL.Name),
}

s, err := service.New(&config)
Expand Down
43 changes: 43 additions & 0 deletions tools/preconf-rpc/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"log/slog"
"math/big"
"net/http"
"strings"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
bidderapiv1 "github.com/primev/mev-commit/p2p/gen/go/bidderapi/v1"
"github.com/primev/mev-commit/tools/preconf-rpc/sender"
"github.com/primev/mev-commit/x/util"
)
Expand Down Expand Up @@ -222,6 +224,42 @@ func buildType(t txnInfo) string {
}
}

func buildConstraint(t txnInfo) string {
if t.txn.Constraint == nil {
return "None"
}
str := strings.Builder{}
switch t.txn.Constraint.Basis {
case bidderapiv1.PositionConstraint_BASIS_ABSOLUTE:
str.WriteString(fmt.Sprintf("Position %d", t.txn.Constraint.Value))
switch t.txn.Constraint.Anchor {
case bidderapiv1.PositionConstraint_ANCHOR_TOP:
str.WriteString(" from Top")
case bidderapiv1.PositionConstraint_ANCHOR_BOTTOM:
str.WriteString(" from Bottom")
}
case bidderapiv1.PositionConstraint_BASIS_PERCENTILE:
switch t.txn.Constraint.Anchor {
case bidderapiv1.PositionConstraint_ANCHOR_TOP:
str.WriteString("Top ")
case bidderapiv1.PositionConstraint_ANCHOR_BOTTOM:
str.WriteString("Bottom ")
}
str.WriteString(fmt.Sprintf("%d%%", t.txn.Constraint.Value))
case bidderapiv1.PositionConstraint_BASIS_GAS_PERCENTILE:
switch t.txn.Constraint.Anchor {
case bidderapiv1.PositionConstraint_ANCHOR_TOP:
str.WriteString("Top ")
case bidderapiv1.PositionConstraint_ANCHOR_BOTTOM:
str.WriteString("Bottom ")
}
str.WriteString(fmt.Sprintf("Gas Percentile %d%%", t.txn.Constraint.Value))
default:
str.WriteString(" Unknown Basis")
}
return str.String()
}

func (n *Notifier) StartTransactionNotifier(
ctx context.Context,
) <-chan struct{} {
Expand Down Expand Up @@ -258,6 +296,11 @@ func (n *Notifier) StartTransactionNotifier(
Field{Title: "Attempts", Value: fmt.Sprintf("%d", t.noOfAttempts), Short: true},
Field{Title: "Duration", Value: t.timeTaken.String(), Short: true},
)
if t.txn.Constraint != nil {
fields = append(fields,
Field{Title: "Constraint", Value: buildConstraint(t), Short: true},
)
}
}
message := Message{
Text: "🚀 Transaction Report",
Expand Down
Loading
Loading