Skip to content

Commit

Permalink
rough sketch: add abi encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarzzz committed Dec 16, 2023
1 parent 2bccb8f commit e549d93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
33 changes: 24 additions & 9 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ func executableDataToCapellaExecutionPayload(data *engine.ExecutableData) (*spec
}, nil
}

type SubmissionResults struct {
StatusCode uint64
Destination string
RoundTripTime *big.Int
Response string
}

func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []byte) ([]byte, error) {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(3*time.Second))
defer cancel()
Expand Down Expand Up @@ -408,19 +415,27 @@ func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []b

elapsed := time.Since(start)

results := struct {
StatusCode int `json:"statusCode"`
Destination string `json:"destination"`
RoundTripTime time.Duration `json:"roundTripTime"`
Response string `json:"reponse"`
}{
StatusCode: resp.StatusCode,
// Create the SubmissionResults struct
results := SubmissionResults{
StatusCode: uint64(resp.StatusCode),
Destination: url,
RoundTripTime: elapsed,
RoundTripTime: big.NewInt(int64(elapsed)),
Response: string(bodyBytes),
}

return json.Marshal(results)
// Pack the data using ABI
arguments := abi.Arguments{

Check failure on line 427 in core/vm/contracts_suave_eth.go

View workflow job for this annotation

GitHub Actions / Build

undefined: abi
{Type: abi.Uint64},

Check failure on line 428 in core/vm/contracts_suave_eth.go

View workflow job for this annotation

GitHub Actions / Build

missing type in composite literal
{Type: abi.String},

Check failure on line 429 in core/vm/contracts_suave_eth.go

View workflow job for this annotation

GitHub Actions / Build

missing type in composite literal
{Type: abi.BigInt},

Check failure on line 430 in core/vm/contracts_suave_eth.go

View workflow job for this annotation

GitHub Actions / Build

missing type in composite literal
{Type: abi.String},

Check failure on line 431 in core/vm/contracts_suave_eth.go

View workflow job for this annotation

GitHub Actions / Build

missing type in composite literal
}
encodedData, err := arguments.Pack(results.StatusCode, results.Destination, results.RoundTripTime, results.Response)
if err != nil {
return nil, fmt.Errorf("failed to ABI encode the data: %v", err)
}

return encodedData, nil
}

func (c *suaveRuntime) fillMevShareBundle(bidId types.BidId) ([]byte, error) {
Expand Down
12 changes: 10 additions & 2 deletions suave/sol/standard_peekers/bids.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ contract BundleBidContract is AnyBidContract {

contract EthBundleSenderContract is BundleBidContract {
string[] public builderUrls;
bytes[] public submissionResults;
SubmissionResults[] public submissionResults;

event SubmissionEvent(bytes[] submissionResults);
event SubmissionEvent(SubmissionResults[] submissionResults);

struct SubmissionResults {
uint64 statusCode;
string destination;
uint256 roundTripTime;
string response;
}


constructor(string[] memory builderUrls_) {
Expand All @@ -71,6 +78,7 @@ contract EthBundleSenderContract is BundleBidContract {

for (uint256 i = 0; i < builderUrls.length; i++) {
submissionDetails = Suave.submitBundleJsonRPC(builderUrls[i], "eth_sendBundle", bundleData);
(uint64 statusCode, string memory destination, uint256 roundTripTime, string memory response) = abi.decode(submissionDetails, (uint64, string, uint256, string));
submissionResults.push(submissionDetails);
}
return bytes.concat(this.emitAndReturnWithResults.selector, abi.encode(bid, submissionResults));
Expand Down

0 comments on commit e549d93

Please sign in to comment.