44 "context"
55 "crypto/ecdsa"
66 "encoding/binary"
7- "encoding/hex"
87 "encoding/json"
98 "errors"
109 "fmt"
@@ -24,16 +23,12 @@ import (
2423
2524 "go.uber.org/zap"
2625
27- "github.com/ethereum/go-ethereum/accounts/abi/bind"
2826 ethcommon "github.com/ethereum/go-ethereum/common"
2927 ethtypes "github.com/ethereum/go-ethereum/core/types"
3028 "github.com/ethereum/go-ethereum/crypto"
3129
3230 "go.opentelemetry.io/otel/attribute"
3331 otelapi "go.opentelemetry.io/otel/metric"
34-
35- // from https://github.com/flashbots/flashtestations/blob/7cc7f68492fe672a823dd2dead649793aac1f216/flashtestations/src/contracts/BlockBuilderPolicy.sol
36- "github.com/flashbots/chain-monitor/contracts"
3732)
3833
3934type L2 struct {
@@ -49,12 +44,8 @@ type L2 struct {
4944 flashtestationsRegistryAddr ethcommon.Address
5045 flashtestationsRegistrySignature [4 ]byte
5146 flashtestationsRegistryEventSignature ethcommon.Hash
52- blockBuilderOwnerKey * ecdsa.PrivateKey
5347 registeredTx chan ethcommon.Hash
5448
55- registryContract * contracts.FlashtestationsRegistry
56- blockBuilderPolicyContract * contracts.BlockBuilderPolicy
57-
5849 flashblockNumberAddr ethcommon.Address
5950 flashblockNumberSignature [4 ]byte
6051
@@ -134,11 +125,6 @@ func newL2(cfg *config.L2) (*L2, error) {
134125 )
135126 }
136127 copy (l2 .builderPolicyAddr [:], addr )
137- blockBuilderPolicyContract , err := contracts .NewBlockBuilderPolicy (ethcommon .BytesToAddress (addr ), l2 .rpc .Main )
138- if err != nil {
139- return nil , err
140- }
141- l2 .blockBuilderPolicyContract = blockBuilderPolicyContract
142128 }
143129
144130 if cfg .MonitorBuilderPolicyContractFunctionSignature != "" {
@@ -158,11 +144,6 @@ func newL2(cfg *config.L2) (*L2, error) {
158144 )
159145 }
160146 copy (l2 .flashtestationsRegistryAddr [:], addr )
161- flashtestationsRegistryContract , err := contracts .NewFlashtestationsRegistry (ethcommon .BytesToAddress (addr ), l2 .rpc .Main )
162- if err != nil {
163- return nil , err
164- }
165- l2 .registryContract = flashtestationsRegistryContract
166147 }
167148
168149 if cfg .MonitorFlashtestationRegistryFunctionSignature != "" {
@@ -205,15 +186,6 @@ func newL2(cfg *config.L2) (*L2, error) {
205186 l2 .monitorResetTicker = time .NewTicker (cfg .ProbeTx .ResetInterval )
206187 }
207188
208- if cfg .AuthorizeWorkloadIdTx .PrivateKey != "" { // blockBuilderOwnerKey
209- blockBuilderOwnerKey , err := crypto .HexToECDSA (cfg .AuthorizeWorkloadIdTx .PrivateKey )
210- if err != nil {
211- return nil , err
212- }
213- l2 .blockBuilderOwnerKey = blockBuilderOwnerKey
214- l2 .registeredTx = make (chan ethcommon.Hash )
215- }
216-
217189 for name , addrStr := range cfg .MonitorWalletAddresses { // wallets
218190 var addr ethcommon.Address
219191 addrBytes , err := ethcommon .ParseHexOrString (addrStr )
@@ -957,33 +929,6 @@ func (l2 *L2) observeWallets(ctx context.Context, o otelapi.Observer) error {
957929 return utils .FlattenErrors (errs )
958930}
959931
960- func (l2 * L2 ) authorizeWorkloadId (ctx context.Context , workloadId [32 ]byte ) error {
961- l := logutils .LoggerFromContext (ctx )
962- from := crypto .PubkeyToAddress (l2 .blockBuilderOwnerKey .PublicKey )
963- tx , err := l2 .blockBuilderPolicyContract .AddWorkloadToPolicy (& bind.TransactOpts {Context : ctx , From : from }, workloadId , "commitHash" , []string {"sourceLocator" })
964- if err != nil {
965- l .Warn ("Failed to authorize workload id" ,
966- zap .Error (err ),
967- )
968- return err
969- }
970- signedTx , err := ethtypes .SignTx (tx , l2 .signer , l2 .blockBuilderOwnerKey )
971- if err != nil {
972- l .Warn ("Failed to sign a transaction" ,
973- zap .Error (err ),
974- )
975- return err
976- }
977- err = l2 .rpc .SendTransaction (ctx , signedTx )
978- if err != nil {
979- l .Warn ("Failed to send a transaction" ,
980- zap .Error (err ),
981- )
982- return err
983- }
984- return nil
985- }
986-
987932func (l2 * L2 ) observerProbes (_ context.Context , o otelapi.Observer ) error {
988933 if l2 .cfg .ProbeTx .PrivateKey == "" {
989934 return nil
@@ -1166,45 +1111,17 @@ func (l2 *L2) handleRegistrationTx(ctx context.Context, txHash ethcommon.Hash) {
11661111
11671112 teeAddress , err := l2 .getTEEAddressFromTx (ctx , txHash )
11681113 if err != nil {
1169- l .Warn ("Failed to get register tee transaction receipt" ,
1114+ l .Warn ("Failed to get register flashtestations transaction receipt" ,
11701115 zap .Error (err ),
11711116 zap .String ("tx" , txHash .Hex ()),
11721117 )
11731118 return
11741119 }
11751120
1176- _ , registration , err := l2 .registryContract .GetRegistration (& bind.CallOpts {Context : ctx }, teeAddress )
1177- if err != nil {
1178- l .Warn ("Failed to get registration" ,
1179- zap .Error (err ),
1180- zap .String ("teeAddress" , teeAddress .Hex ()),
1181- )
1182- return
1183- }
1184- workloadId , err := l2 .blockBuilderPolicyContract .WorkloadIdForTDRegistration (& bind.CallOpts {Context : ctx }, registration )
1185- if err != nil {
1186- l .Warn ("Failed to get workload id" ,
1187- zap .Error (err ),
1188- zap .String ("teeAddress" , teeAddress .Hex ()),
1189- )
1190- return
1191- }
1192-
1193- if l2 .blockBuilderOwnerKey != nil {
1194- err = l2 .authorizeWorkloadId (ctx , workloadId )
1195- if err != nil {
1196- l .Warn ("Failed to authorize workload id" ,
1197- zap .Error (err ),
1198- )
1199- }
1200- }
1201-
1202- l2 .workloadId = workloadId
1203-
12041121 metrics .RegisteredFlashtestationsCount .Record (ctx , 1 , otelapi .WithAttributes (
12051122 attribute.KeyValue {Key : "kind" , Value : attribute .StringValue ("l2" )},
12061123 attribute.KeyValue {Key : "network_id" , Value : attribute .Int64Value (l2 .chainID .Int64 ())},
1207- attribute.KeyValue {Key : "workload_id " , Value : attribute .StringValue (hex . EncodeToString ( workloadId [:] ))},
1124+ attribute.KeyValue {Key : "tee_address " , Value : attribute .StringValue (teeAddress . Hex ( ))},
12081125 ))
12091126
12101127 return
0 commit comments