Skip to content

Commit

Permalink
save execution revert results for sbundles (#34)
Browse files Browse the repository at this point in the history
* save execution revert results for sbundles

* improve visibility

* fix lint & test

* lint fixes
  • Loading branch information
TymKh authored May 6, 2024
1 parent 3bbdf2b commit c099cc0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ jobs:
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v2

- name: Install gofumpt
run: go install mvdan.cc/gofumpt@v0.4.0
run: go install mvdan.cc/gofumpt@v0.5.0

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.2
run: go install honnef.co/go/tools/cmd/staticcheck@2023.1.7

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2

- name: Lint
run: make lint
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ linters:
- varcheck
- exhaustruct
- nolintlint
- depguard
- testifylint
- perfsprint
- gofumpt

#
# Disabled because of generics:
Expand Down
2 changes: 1 addition & 1 deletion mevshare/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (m *API) SendBundle(ctx context.Context, bundle SendMevBundleArgs) (_ SendM
}
bundle.Validity.Refund = []RefundConstraint{{0, refundPercent}}
MergePrivacyBuilders(&bundle)
err = MergeInclusionIntervals(&bundle.Inclusion, &unmatchedBundle.Inclusion)
err = MergeInclusionIntervals(&bundle.Inclusion, unmatchedBundle.Inclusion)
if err != nil {
return SendMevBundleResponse{}, ErrBackrunInclusion
}
Expand Down
2 changes: 1 addition & 1 deletion mevshare/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (b *BuildersBackend) SendBundle(ctx context.Context, logger *zap.Logger, bu
}
cleanBundle(&args)

//for internal builders send signing_address
// for internal builders send signing_address
iArgs := &SendMevBundleArgs{
Version: args.Version,
Inclusion: args.Inclusion,
Expand Down
4 changes: 2 additions & 2 deletions mevshare/bundle_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func cleanBody(bundle *SendMevBundleArgs) {

// MergeInclusionIntervals writes to the topLevel inclusion value of overlap between inner and topLevel
// or return error if there is no overlap
func MergeInclusionIntervals(topLevel, inner *MevBundleInclusion) error {
func MergeInclusionIntervals(topLevel *MevBundleInclusion, inner MevBundleInclusion) error {
if topLevel.MaxBlock < inner.BlockNumber || inner.MaxBlock < topLevel.BlockNumber {
return ErrInvalidInclusion
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func validateBundleInner(level int, bundle *SendMevBundleArgs, currentBlock uint
bodyHashes = append(bodyHashes, tx.Hash())
txs++
} else if el.Bundle != nil {
err = MergeInclusionIntervals(&bundle.Inclusion, &el.Bundle.Inclusion)
err = MergeInclusionIntervals(&bundle.Inclusion, el.Bundle.Inclusion)
if err != nil {
return hash, txs, unmatched, err
}
Expand Down
5 changes: 3 additions & 2 deletions mevshare/bundle_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ func TestMergeInclusionIntervals(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
bottomCopy := c.bottom
err := MergeInclusionIntervals(&c.top, &bottomCopy)
topCopy := c.top
err := MergeInclusionIntervals(&topCopy, bottomCopy)
if c.err != nil {
require.ErrorIs(t, err, c.err)
} else {
require.NoError(t, err)
}
require.Equal(t, c.expectedTop, c.top)
require.Equal(t, c.expectedTop, topCopy)
require.Equal(t, c.bottom, bottomCopy)
})
}
Expand Down
13 changes: 10 additions & 3 deletions mevshare/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ type DBSbundle struct {
BodySize int `db:"body_size"`
OriginID sql.NullString `db:"origin_id"`
InsertedAt time.Time `db:"inserted_at"`
ExecError sql.NullString `db:"exec_error"`
Revert []byte `db:"revert"`
}

var insertBundleQuery = `
INSERT INTO sbundle (hash, matching_hash, signer, cancelled, allow_matching, prematched, received_at,
sim_success, sim_error, simulated_at, sim_eff_gas_price, sim_profit, sim_refundable_value, sim_gas_used,
sim_all_sims_gas_used, sim_total_sim_count,
body, body_size, origin_id)
body, body_size, origin_id, exec_error, revert)
VALUES (:hash, :matching_hash, :signer, :cancelled, :allow_matching, :prematched, :received_at,
:sim_success, :sim_error, :simulated_at, :sim_eff_gas_price, :sim_profit, :sim_refundable_value, :sim_gas_used,
:sim_all_sims_gas_used, :sim_total_sim_count,
:body, :body_size, :origin_id)
:body, :body_size, :origin_id, :exec_error, :revert)
ON CONFLICT (hash) DO NOTHING
RETURNING hash`

Expand All @@ -68,7 +70,7 @@ var updateBundleSimQuery = `
UPDATE sbundle
SET sim_success = :sim_success, sim_error = :sim_error, simulated_at = :simulated_at,
sim_eff_gas_price = :sim_eff_gas_price, sim_profit = :sim_profit, sim_refundable_value = :sim_refundable_value,
sim_gas_used = :sim_gas_used, sim_all_sims_gas_used = :sim_all_sims_gas_used, sim_total_sim_count = :sim_total_sim_count, body = :body
sim_gas_used = :sim_gas_used, sim_all_sims_gas_used = :sim_all_sims_gas_used, sim_total_sim_count = :sim_total_sim_count, body = :body, exec_error = :exec_error, revert = :revert
WHERE hash = :hash`

var getBundleQuery = `
Expand Down Expand Up @@ -223,6 +225,9 @@ func (b *DBBackend) InsertBundleForStats(ctx context.Context, bundle *SendMevBun
if err != nil {
return known, err
}
dbBundle.ExecError = sql.NullString{String: result.ExecError, Valid: result.ExecError != ""}
dbBundle.Revert = result.Revert

dbBundle.BodySize = len(bundle.Body)
dbBundle.OriginID = sql.NullString{String: bundle.Metadata.OriginID, Valid: bundle.Metadata.OriginID != ""}

Expand Down Expand Up @@ -261,6 +266,8 @@ func (b *DBBackend) InsertBundleForStats(ctx context.Context, bundle *SendMevBun
storedBundle.SimProfit = sql.NullString{String: dbIntToEth(&result.Profit), Valid: result.Success}
storedBundle.SimRefundableValue = sql.NullString{String: dbIntToEth(&result.RefundableValue), Valid: result.Success}
storedBundle.SimGasUsed = sql.NullInt64{Int64: int64(result.GasUsed), Valid: true}
storedBundle.ExecError = sql.NullString{String: result.ExecError, Valid: result.ExecError != ""}
storedBundle.Revert = result.Revert
}

if storedBundle.SimTotalSimCount.Valid {
Expand Down
2 changes: 2 additions & 0 deletions mevshare/sim_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (w *SimulationWorker) Process(ctx context.Context, data []byte, info simque
zap.String("eth_refundable_value", formatUnits(result.RefundableValue.ToInt(), "eth")),
zap.Uint64("gas_used", uint64(result.GasUsed)),
zap.Uint64("state_block", uint64(result.StateBlock)),
zap.String("exec_error", result.ExecError),
zap.String("revert", result.Revert.String()),
zap.Int("retries", info.Retries),
)

Expand Down
2 changes: 2 additions & 0 deletions mevshare/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ type SimMevBundleResponse struct {
RefundableValue hexutil.Big `json:"refundableValue"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
BodyLogs []SimMevBodyLogs `json:"logs,omitempty"`
ExecError string `json:"execError,omitempty"`
Revert hexutil.Bytes `json:"revert,omitempty"`
}

type SimMevBundleAuxArgs struct {
Expand Down
2 changes: 2 additions & 0 deletions sql/004_revert_fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE sbundle ADD COLUMN exec_error TEXT;
ALTER TABLE sbundle ADD COLUMN revert BYTEA;

0 comments on commit c099cc0

Please sign in to comment.