Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC : Request results pattern #131

Closed
wants to merge 2 commits into from
Closed
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
35 changes: 33 additions & 2 deletions core/vm/contracts_suave_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@
}, nil
}

type SubmissionResults struct {
StatusCode uint64
Destination string
RoundTripTime *big.Int
Copy link
Contributor

@metachris metachris Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of bigInt complexity, perhaps go for uint64 in millis? or alternatively record startTimeUnix and endTimeUnix 🤔

also the unit here should be self-apparent

Copy link
Member Author

@dmarzzz dmarzzz Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally, great suggestions! just threw together something quick to illustrate

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 @@ -388,23 +395,47 @@
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 {
return formatPeekerError("could not send request to relay: %w", err)
}
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)
}

return formatPeekerError("request failed with code %d: %s", resp.StatusCode, string(bodyBytes))
}

return nil, nil
elapsed := time.Since(start)

// Create the SubmissionResults struct
results := SubmissionResults{
StatusCode: uint64(resp.StatusCode),
Destination: url,
RoundTripTime: big.NewInt(int64(elapsed)),
Response: string(bodyBytes),
}

// 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
25 changes: 22 additions & 3 deletions suave/sol/standard_peekers/bids.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,41 @@ contract BundleBidContract is AnyBidContract {

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

event SubmissionEvent(SubmissionResults[] submissionResults);

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


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);
(uint64 statusCode, string memory destination, uint256 roundTripTime, string memory response) = abi.decode(submissionDetails, (uint64, string, uint256, string));
submissionResults.push(submissionDetails);
}

return BundleBidContract.emitAndReturn(bid, bundleData);
return bytes.concat(this.emitAndReturnWithResults.selector, abi.encode(bid, submissionResults));
}
}

Expand Down
Loading