Skip to content

Commit d3d4bfb

Browse files
committed
Add monitoring and automate add workload id for flashtestations
1 parent b8c684b commit d3d4bfb

File tree

12 files changed

+4244
-47
lines changed

12 files changed

+4244
-47
lines changed

cmd/serve.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ func CommandServe(cfg *config.Config) *cli.Command {
9191
Value: 4,
9292
},
9393

94+
&cli.Int64Flag{ // --l2-flashtestations-per-block
95+
Category: strings.ToUpper(categoryL2),
96+
Destination: &cfg.L2.FlashtestationsPerBlock,
97+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_FLASHTESTATIONS_PER_BLOCK"},
98+
Name: categoryL2 + "-flashtestations-per-block",
99+
Usage: "expected count of flashtestations per block on l2",
100+
Value: 1,
101+
},
102+
94103
&cli.Uint64Flag{
95104
Category: strings.ToUpper(categoryL2),
96105
Destination: &cfg.L2.GenesisTime,
@@ -122,9 +131,59 @@ func CommandServe(cfg *config.Config) *cli.Command {
122131
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_BUILDER_POLICY_CONTRACT_FUNCTION_SIGNATURE"},
123132
Name: categoryL2 + "-monitor-builder-policy-contract-function-signature",
124133
Usage: "l2 builder flashtestations policy contract function `signature` to monitor",
125-
Value: "verifyBlockBuilderProof(uint8,bytes32)",
134+
Value: "permitVerifyBlockBuilderProof(uint8,bytes32,uint256,bytes)",
135+
},
136+
137+
&cli.StringFlag{ // --l2-monitor-flashtestations-registry-contract
138+
Category: strings.ToUpper(categoryL2),
139+
Destination: &cfg.L2.MonitorFlashtestationRegistryContract,
140+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_FLASHTESTATIONS_REGISTRY_CONTRACT"},
141+
Name: categoryL2 + "-monitor-flashtestations-registry-contract",
142+
Usage: "l2 builder flashtestations registry contract `address` to monitor",
143+
},
144+
145+
&cli.StringFlag{ // --l2-monitor-flashtestations-registry-function-signature
146+
Category: strings.ToUpper(categoryL2),
147+
Destination: &cfg.L2.MonitorFlashtestationRegistryFunctionSignature,
148+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_FLASHTESTATIONS_REGISTRY_CONTRACT_FUNCTION_SIGNATURE"},
149+
Name: categoryL2 + "-monitor-flashtestations-registry-contract-function-signature",
150+
Usage: "l2 builder flashtestations registry contract function `signature` to monitor",
151+
Value: "permitRegisterTEEService(bytes,bytes,uint256,uint256,bytes)",
152+
},
153+
154+
&cli.StringFlag{ // --l2-monitor-flashtestations-registry-event-signature
155+
Category: strings.ToUpper(categoryL2),
156+
Destination: &cfg.L2.MonitorFlashtestationRegistryEventSignature,
157+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_FLASHTESTATIONS_REGISTRY_CONTRACT_FUNCTION_SIGNATURE"},
158+
Name: categoryL2 + "-monitor-flashtestations-registry-contract-function-signature",
159+
Usage: "l2 builder flashtestations registry contract event `signature` to monitor",
160+
Value: "TEEServiceRegistered(address,bytes,bool)",
126161
},
127162

163+
&cli.StringFlag{ // --l2-builder-policy-owner-private-key
164+
Category: strings.ToUpper(categoryL2),
165+
Destination: &cfg.L2.AuthorizeWorkloadIdTx.PrivateKey,
166+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_BUILDER_POLICY_OWNER_PRIVATE_KEY"},
167+
Name: categoryL2 + "-builder-policy-owner-private-key",
168+
Usage: "builder policy owner private `key` to authorize the builder's workload id",
169+
},
170+
171+
&cli.StringFlag{ // --l2-monitor-flashblock-number-contract
172+
Category: strings.ToUpper(categoryL2),
173+
Destination: &cfg.L2.MonitorFlashblockNumberContract,
174+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_FLASHBLOCK_NUMBER_CONTRACT"},
175+
Name: categoryL2 + "-monitor-flashblock-number-contract",
176+
Usage: "l2 builder flashblock number contract `address` to monitor",
177+
},
178+
179+
&cli.StringFlag{ // --l2-monitor-flashblock-number-contract-function-signature
180+
Category: strings.ToUpper(categoryL2),
181+
Destination: &cfg.L2.MonitorFlashblockNumberContractFunctionSignature,
182+
EnvVars: []string{envPrefix + strings.ToUpper(categoryL2) + "_MONITOR_FLASHBLOCK_NUMBER_CONTRACT_FUNCTION_SIGNATURE"},
183+
Name: categoryL2 + "-monitor-flashblock-number-contract-function-signature",
184+
Usage: "l2 builder flashblock number contract function `signature` to monitor",
185+
Value: "incrementFlashblockNumber()",
186+
},
128187
&cli.StringFlag{ // --l2-monitor-flashblock-number-contract
129188
Category: strings.ToUpper(categoryL2),
130189
Destination: &cfg.L2.MonitorFlashblockNumberContract,

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func New() *Config {
2626
L2: &L2{
2727
Dir: dir,
2828
ProbeTx: &ProbeTx{},
29+
AuthorizeWorkloadIdTx: &AuthorizeWorkloadIdTx{},
2930
},
3031
}
3132
}

config/l2.go

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,43 @@ import (
1313
type L2 struct {
1414
Dir *Dir `yaml:"-"`
1515

16-
BlockTime time.Duration `yaml:"block_time"`
17-
FlashblocksPerBlock int64 `yaml:"flashblocks_per_block"`
18-
GenesisTime uint64 `yaml:"genesis_time"`
19-
NetworkID uint64 `yaml:"network_id"`
20-
ReorgWindow time.Duration `yaml:"reorg_window"`
21-
Rpc string `yaml:"rpc"`
22-
RpcFallback []string `yaml:"rpc_fallback"`
16+
BlockTime time.Duration `yaml:"block_time"`
17+
FlashblocksPerBlock int64 `yaml:"flashblocks_per_block"`
18+
FlashtestationsPerBlock int64 `yaml:"flashtestations_per_block"`
19+
GenesisTime uint64 `yaml:"genesis_time"`
20+
NetworkID uint64 `yaml:"network_id"`
21+
ReorgWindow time.Duration `yaml:"reorg_window"`
22+
Rpc string `yaml:"rpc"`
23+
RpcFallback []string `yaml:"rpc_fallback"`
2324

2425
MonitorBuilderAddress string `yaml:"monitor_builder_address"`
2526
MonitorBuilderPolicyContract string `yaml:"monitor_builder_policy_contract"`
2627
MonitorBuilderPolicyContractFunctionSignature string `yaml:"monitor_builder_policy_contract_function_signature"`
2728
MonitorFlashblockNumberContract string `yaml:"monitor_builder_flashblock_number_contract"`
2829
MonitorFlashblockNumberContractFunctionSignature string `yaml:"monitor_builder_flashblock_number_contract_function_signature"`
30+
MonitorFlashtestationRegistryContract string `yaml:"monitor_flashtestation_registry_contract"`
31+
MonitorFlashtestationRegistryFunctionSignature string `yaml:"monitor_flashtestation_registry_function_signature"`
32+
MonitorFlashtestationRegistryEventSignature string `yaml:"monitor_flashtestation_registry_event_signature"`
2933
MonitorTxReceipts bool `yaml:"monitor_tx_receipts"`
3034
MonitorWalletAddresses map[string]string `yaml:"monitor_wallet_addresses"`
3135

32-
ProbeTx *ProbeTx `yaml:"probe"`
36+
ProbeTx *ProbeTx `yaml:"probe"`
37+
AuthorizeWorkloadIdTx *AuthorizeWorkloadIdTx `yaml:"authorize_workload_id"`
3338
}
3439

3540
const (
3641
maxReorgWindow = 24 * time.Hour
3742
)
3843

3944
var (
40-
errL2InvalidBuilderAddress = errors.New("invalid l2 builder address")
41-
errL2InvalidBuilderPolicyContact = errors.New("invalid l2 builder policy contract address")
42-
errL2InvalidFlashblockNumberContact = errors.New("invalid l2 flashblocks number contract address")
43-
errL2InvalidRpc = errors.New("invalid l2 rpc url")
44-
errL2InvalidRpcFallback = errors.New("invalid l2 fallback rpc url")
45-
errL2InvalidWalletAddress = errors.New("invalid l2 wallet address")
46-
errL2ReorgWindowTooLarge = errors.New("l2 reorg window is too large")
45+
errL2InvalidBuilderAddress = errors.New("invalid l2 builder address")
46+
errL2InvalidBuilderPolicyContact = errors.New("invalid l2 builder policy contract address")
47+
errL2InvalidFlashtestationsRegistryContact = errors.New("invalid l2 flashtestations registry contract address")
48+
errL2InvalidFlashblockNumberContact = errors.New("invalid l2 flashblocks number contract address")
49+
errL2InvalidRpc = errors.New("invalid l2 rpc url")
50+
errL2InvalidRpcFallback = errors.New("invalid l2 fallback rpc url")
51+
errL2InvalidWalletAddress = errors.New("invalid l2 wallet address")
52+
errL2ReorgWindowTooLarge = errors.New("l2 reorg window is too large")
4753
)
4854

4955
func (cfg *L2) Validate() error {
@@ -121,6 +127,26 @@ func (cfg *L2) Validate() error {
121127
}
122128
}
123129

130+
{ // monitor_flashtestations_registry_contract
131+
if cfg.MonitorFlashtestationRegistryContract != "" {
132+
_addr, err := ethcommon.ParseHexOrString(cfg.MonitorFlashtestationRegistryContract)
133+
if err != nil {
134+
errs = append(errs, fmt.Errorf("%w: %s: %w",
135+
errL2InvalidFlashtestationsRegistryContact,
136+
cfg.MonitorFlashtestationRegistryContract,
137+
err,
138+
))
139+
}
140+
if len(_addr) != 20 {
141+
errs = append(errs, fmt.Errorf("%w: %s: invalid length (want 20, got %d)",
142+
errL2InvalidFlashtestationsRegistryContact,
143+
cfg.MonitorFlashtestationRegistryContract,
144+
len(_addr),
145+
))
146+
}
147+
}
148+
}
149+
124150
{ // monitor_builder_flashblock_number_contract
125151
if cfg.MonitorFlashblockNumberContract != "" {
126152
_addr, err := ethcommon.ParseHexOrString(cfg.MonitorFlashblockNumberContract)

config/workload_id_tx.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package config
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/ethereum/go-ethereum/crypto"
8+
"github.com/flashbots/chain-monitor/utils"
9+
)
10+
11+
type AuthorizeWorkloadIdTx struct {
12+
PrivateKey string `yaml:"private_key"`
13+
}
14+
15+
var (
16+
errL2InvalidFlashtestaionsOwnerPrivateKey = errors.New("invalid flashtestations owner private key")
17+
)
18+
19+
func (cfg *AuthorizeWorkloadIdTx) Validate() error {
20+
errs := make([]error, 0)
21+
22+
if cfg.PrivateKey != "" {
23+
if _, err := crypto.HexToECDSA(cfg.PrivateKey); err != nil {
24+
errs = append(errs, fmt.Errorf("%w: %w",
25+
errL2InvalidMonitorPrivateKey,
26+
err,
27+
))
28+
}
29+
}
30+
31+
return utils.FlattenErrors(errs)
32+
}

0 commit comments

Comments
 (0)