Skip to content

Commit eb08709

Browse files
authored
Add flag to watch for proposer builds (#10)
1 parent e84d83c commit eb08709

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ Options:
3535
- `--continue` (bool): Whether to restart the chain from a previous run if the output folder is not empty. It defaults to `false`.
3636
- `--use-bin-path` (bool): Whether to use the binaries from the local path instead of downloading them. It defaults to `false`.
3737
- `--genesis-delay` (int): The delay in seconds before the genesis block is created. It is used to account for the delay between the creation of the artifacts and the running of the services. It defaults to `5` seconds.
38+
- `--watch-payloads` (bool): If enabled, it logs whenever a builder builds a valid block through the relay. It defaults to `false`.
3839

3940
Unless the `--continue` flag is set, the playground will delete the output directory and start a new chain from scratch on every run.

main.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"encoding/json"
99
"fmt"
1010
"html/template"
11+
"io"
1112
"math/big"
13+
"net/http"
1214
"os"
1315
"os/exec"
1416
"os/signal"
@@ -49,6 +51,7 @@ var continueFlag bool
4951
var useBinPathFlag bool
5052
var validateFlag bool
5153
var genesisDelayFlag uint64
54+
var watchPayloadsFlag bool
5255

5356
var rootCmd = &cobra.Command{
5457
Use: "playground",
@@ -153,6 +156,7 @@ func main() {
153156
rootCmd.Flags().BoolVar(&continueFlag, "continue", false, "")
154157
rootCmd.Flags().BoolVar(&useBinPathFlag, "use-bin-path", false, "")
155158
rootCmd.Flags().Uint64Var(&genesisDelayFlag, "genesis-delay", 5, "")
159+
rootCmd.Flags().BoolVar(&watchPayloadsFlag, "watch-payloads", false, "")
156160

157161
downloadArtifactsCmd.Flags().BoolVar(&validateFlag, "validate", false, "")
158162
validateCmd.Flags().Uint64Var(&numBlocksValidate, "num-blocks", 5, "")
@@ -207,6 +211,10 @@ func runIt() error {
207211
return err
208212
}
209213

214+
if watchPayloadsFlag {
215+
go watchProposerPayloads()
216+
}
217+
210218
sig := make(chan os.Signal, 1)
211219
signal.Notify(sig, os.Interrupt)
212220

@@ -781,3 +789,48 @@ func getHomeDir() (string, error) {
781789

782790
return customHomeDir, nil
783791
}
792+
793+
func watchProposerPayloads() {
794+
// This is not the most efficient solution since we are querying the endpoint for the full list of payloads
795+
// every 2 seconds. It should be fine for the kind of workloads expected to run.
796+
797+
lastSlot := uint64(0)
798+
799+
for {
800+
time.Sleep(2 * time.Second)
801+
802+
vals, err := getProposerPayloadDelivered()
803+
if err != nil {
804+
fmt.Println("Error getting proposer payloads:", err)
805+
continue
806+
}
807+
808+
for _, val := range vals {
809+
if val.Slot <= lastSlot {
810+
continue
811+
}
812+
813+
fmt.Printf("Block Proposed: Slot: %d, Builder: %s, Block: %d\n", val.Slot, val.BuilderPubkey, val.BlockNumber)
814+
lastSlot = val.Slot
815+
}
816+
}
817+
}
818+
819+
func getProposerPayloadDelivered() ([]*mevRCommon.BidTraceV2JSON, error) {
820+
resp, err := http.Get("http://localhost:5555/relay/v1/data/bidtraces/proposer_payload_delivered")
821+
if err != nil {
822+
return nil, err
823+
}
824+
defer resp.Body.Close()
825+
826+
data, err := io.ReadAll(resp.Body)
827+
if err != nil {
828+
return nil, err
829+
}
830+
831+
var payloadDeliveredList []*mevRCommon.BidTraceV2JSON
832+
if err := json.Unmarshal(data, &payloadDeliveredList); err != nil {
833+
return nil, err
834+
}
835+
return payloadDeliveredList, nil
836+
}

0 commit comments

Comments
 (0)