From 2bccb8fee020c98b1fdd3b64965783ab6d0686d5 Mon Sep 17 00:00:00 2001 From: dmarzzz Date: Sat, 16 Dec 2023 13:35:21 +0800 Subject: [PATCH] not working demo --- core/vm/contracts_suave_eth.go | 20 ++++++++++++++++++-- suave/sol/standard_peekers/bids.sol | 17 ++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/core/vm/contracts_suave_eth.go b/core/vm/contracts_suave_eth.go index ac2b9be5f7..8719346413 100644 --- a/core/vm/contracts_suave_eth.go +++ b/core/vm/contracts_suave_eth.go @@ -388,6 +388,7 @@ func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []b req.Header.Add("Accept", "application/json") req.Header.Add("X-Flashbots-Signature", signature) + start := time.Now() // Execute request resp, err := http.DefaultClient.Do(req) if err != nil { @@ -395,8 +396,9 @@ func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []b } defer resp.Body.Close() + var bodyBytes []byte if resp.StatusCode > 299 { - bodyBytes, err := io.ReadAll(resp.Body) + bodyBytes, err = io.ReadAll(resp.Body) if err != nil { return formatPeekerError("request failed with code %d", resp.StatusCode) } @@ -404,7 +406,21 @@ func (c *suaveRuntime) submitBundleJsonRPC(url string, method string, params []b return formatPeekerError("request failed with code %d: %s", resp.StatusCode, string(bodyBytes)) } - return nil, nil + 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, + Destination: url, + RoundTripTime: elapsed, + Response: string(bodyBytes), + } + + return json.Marshal(results) } func (c *suaveRuntime) fillMevShareBundle(bidId types.BidId) ([]byte, error) { diff --git a/suave/sol/standard_peekers/bids.sol b/suave/sol/standard_peekers/bids.sol index 4c866a5a73..4db9e63824 100644 --- a/suave/sol/standard_peekers/bids.sol +++ b/suave/sol/standard_peekers/bids.sol @@ -47,22 +47,33 @@ contract BundleBidContract is AnyBidContract { contract EthBundleSenderContract is BundleBidContract { string[] public builderUrls; + bytes[] public submissionResults; + + event SubmissionEvent(bytes[] submissionResults); + constructor(string[] memory builderUrls_) { builderUrls = builderUrls_; } + function emitAndReturnWithResults(Suave.Bid memory bid, bytes[] memory submissionResults) internal virtual returns (bytes memory) { + emit BidEvent(bid.id, bid.decryptionCondition, bid.allowedPeekers); + emit SubmissionEvent(submissionResults); + } + function emitAndReturn(Suave.Bid memory bid, bytes memory bundleData) internal virtual override returns (bytes memory) { + bytes memory submissionDetails; + for (uint256 i = 0; i < builderUrls.length; i++) { - Suave.submitBundleJsonRPC(builderUrls[i], "eth_sendBundle", bundleData); + submissionDetails = Suave.submitBundleJsonRPC(builderUrls[i], "eth_sendBundle", bundleData); + submissionResults.push(submissionDetails); } - - return BundleBidContract.emitAndReturn(bid, bundleData); + return bytes.concat(this.emitAndReturnWithResults.selector, abi.encode(bid, submissionResults)); } }