diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 721a4b124..3c69796b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,4 +215,5 @@ jobs: needs: - go-modules - foundry - - contracts \ No newline at end of file + - contracts + diff --git a/testing/pkg/orchestrator/orchestrator.go b/testing/pkg/orchestrator/orchestrator.go index 5ae9b081b..47d17a3fe 100644 --- a/testing/pkg/orchestrator/orchestrator.go +++ b/testing/pkg/orchestrator/orchestrator.go @@ -102,7 +102,7 @@ func (n *node) Close() error { return n.conn.Close() } -func newNode(rpcAddr string, logger *slog.Logger) (*node, error) { +func newNode(rpcAddr string, logger *slog.Logger) (any, error) { // Since we don't know if the server has TLS enabled on its rpc // endpoint, we try different strategies from most secure to // least secure. In the future, when only TLS-enabled servers @@ -215,32 +215,36 @@ func (o *orchestrator) Close() error { return errs } -func NewOrchestrator(opts Options) (Orchestrator, error) { - providers := make([]Provider, 0, len(opts.ProviderRPCAddresses)) - for _, rpcAddr := range opts.ProviderRPCAddresses { - n, err := newNode(rpcAddr, opts.Logger) +func createNodes[T any](rpcAddrs []string, logger *slog.Logger) ([]T, error) { + nodes := make([]T, 0, len(rpcAddrs)) + for _, rpcAddr := range rpcAddrs { + n, err := newNode(rpcAddr, logger) if err != nil { return nil, err } - providers = append(providers, n) + tn, ok := n.(T) + if !ok { + return nil, fmt.Errorf("unexpected node type") + } + nodes = append(nodes, tn) } + return nodes, nil +} - bidders := make([]Bidder, 0, len(opts.BidderRPCAddresses)) - for _, rpcAddr := range opts.BidderRPCAddresses { - n, err := newNode(rpcAddr, opts.Logger) - if err != nil { - return nil, err - } - bidders = append(bidders, n) +func NewOrchestrator(opts Options) (Orchestrator, error) { + providers, err := createNodes[Provider](opts.ProviderRPCAddresses, opts.Logger) + if err != nil { + return nil, err } - bootnodes := make([]Bootnode, 0, len(opts.BootnodeRPCAddresses)) - for _, rpcAddr := range opts.BootnodeRPCAddresses { - n, err := newNode(rpcAddr, opts.Logger) - if err != nil { - return nil, err - } - bootnodes = append(bootnodes, n) + bidders, err := createNodes[Bidder](opts.BidderRPCAddresses, opts.Logger) + if err != nil { + return nil, err + } + + bootnodes, err := createNodes[Bootnode](opts.BootnodeRPCAddresses, opts.Logger) + if err != nil { + return nil, err } ethClient, err := ethclient.Dial(opts.SettlementRPCEndpoint) diff --git a/testing/pkg/tests/preconf/preconf.go b/testing/pkg/tests/preconf/preconf.go index c15d72d96..8ed88ac46 100644 --- a/testing/pkg/tests/preconf/preconf.go +++ b/testing/pkg/tests/preconf/preconf.go @@ -292,128 +292,128 @@ DONE: logger.Error("Bid not accepted but preconfs received", "entry", entry) return fmt.Errorf("bid not accepted but preconfs received") } - } else { - if len(entry.Preconfs) != len(cluster.Providers()) { + continue + } + if len(entry.Preconfs) != len(cluster.Providers()) { + logger.Error( + "Bid accepted but not all preconfs received", + "entry", entry, + "preconfs", len(entry.Preconfs), + "providers", len(cluster.Providers()), + ) + return fmt.Errorf("bid accepted but not all preconfs received") + } + winner, ok := store.Get(blkWinnerKey(uint64(entry.Bid.BlockNumber))) + if !ok { + logger.Error("Winner not found", "block", entry.Bid.BlockNumber) + return fmt.Errorf("winner not found") + } + foundCmt := false + for _, pc := range entry.Preconfs { + cmtDigest, err := hex.DecodeString(pc.CommitmentDigest) + if err != nil { logger.Error( - "Bid accepted but not all preconfs received", + "Failed to decode commitment digest", + "error", err, "entry", entry, - "preconfs", len(entry.Preconfs), - "providers", len(cluster.Providers()), + "digest", pc.CommitmentDigest, ) - return fmt.Errorf("bid accepted but not all preconfs received") + return fmt.Errorf("failed to decode commitment digest") } - winner, ok := store.Get(blkWinnerKey(uint64(entry.Bid.BlockNumber))) + ec, ok := store.Get(encryptCmtKey(cmtDigest)) if !ok { - logger.Error("Winner not found", "block", entry.Bid.BlockNumber) - return fmt.Errorf("winner not found") + logger.Error( + "Encrypted commitment not found", + "entry", entry, + "digest", pc.CommitmentDigest, + ) + return fmt.Errorf("encrypted commitment not found") } - foundCmt := false - for _, pc := range entry.Preconfs { - cmtDigest, err := hex.DecodeString(pc.CommitmentDigest) - if err != nil { - logger.Error( - "Failed to decode commitment digest", - "error", err, - "entry", entry, - "digest", pc.CommitmentDigest, - ) - return fmt.Errorf("failed to decode commitment digest") - } - ec, ok := store.Get(encryptCmtKey(cmtDigest)) + providerAddr, err := hex.DecodeString(pc.ProviderAddress) + if err != nil { + logger.Error( + "Failed to decode provider address", + "error", err, + "entry", entry, + "address", pc.ProviderAddress, + ) + return fmt.Errorf("failed to decode provider address") + } + if common.BytesToAddress(providerAddr).Cmp(winner.(*blocktracker.BlocktrackerNewL1Block).Winner) == 0 { + foundCmt = true + ecmt := ec.(*preconfcommitmentstore.PreconfcommitmentstoreUnopenedCommitmentStored) + _, ok := store.Get(openCmtKey(ecmt.CommitmentIndex[:])) if !ok { logger.Error( - "Encrypted commitment not found", + "Opened commitment not found", "entry", entry, - "digest", pc.CommitmentDigest, + "index", hex.EncodeToString(ecmt.CommitmentIndex[:]), ) - return fmt.Errorf("encrypted commitment not found") + return fmt.Errorf("opened commitment not found") } - providerAddr, err := hex.DecodeString(pc.ProviderAddress) - if err != nil { + pcmt, ok := store.Get(settleKey(ecmt.CommitmentIndex[:])) + if !ok { logger.Error( - "Failed to decode provider address", - "error", err, + "Settlement not found", "entry", entry, - "address", pc.ProviderAddress, + "index", hex.EncodeToString(ecmt.CommitmentIndex[:]), ) - return fmt.Errorf("failed to decode provider address") + return fmt.Errorf("settlement not found") } - if common.BytesToAddress(providerAddr).Cmp(winner.(*blocktracker.BlocktrackerNewL1Block).Winner) == 0 { - foundCmt = true - ecmt := ec.(*preconfcommitmentstore.PreconfcommitmentstoreUnopenedCommitmentStored) - _, ok := store.Get(openCmtKey(ecmt.CommitmentIndex[:])) - if !ok { - logger.Error( - "Opened commitment not found", - "entry", entry, - "index", hex.EncodeToString(ecmt.CommitmentIndex[:]), - ) - return fmt.Errorf("opened commitment not found") + if entry.ShouldSlash { + if !pcmt.(*oracle.OracleCommitmentProcessed).IsSlash { + logger.Error("Provider should be slashed", "entry", entry) + return fmt.Errorf("provider should be slashed") } - pcmt, ok := store.Get(settleKey(ecmt.CommitmentIndex[:])) + _, ok := store.Get(fundsRetrievedKey(cmtDigest)) if !ok { - logger.Error( - "Settlement not found", - "entry", entry, - "index", hex.EncodeToString(ecmt.CommitmentIndex[:]), - ) - return fmt.Errorf("settlement not found") + logger.Error("Funds not retrieved", "entry", entry) + return fmt.Errorf("funds not retrieved") } - if entry.ShouldSlash { - if !pcmt.(*oracle.OracleCommitmentProcessed).IsSlash { - logger.Error("Provider should be slashed", "entry", entry) - return fmt.Errorf("provider should be slashed") - } - _, ok := store.Get(fundsRetrievedKey(cmtDigest)) - if !ok { - logger.Error("Funds not retrieved", "entry", entry) - return fmt.Errorf("funds not retrieved") - } - } else { - if pcmt.(*oracle.OracleCommitmentProcessed).IsSlash { - // check if any of the transactions were not successful, - // if so, the provider should not be slashed. Test doesnt - // handle reverting transactions. - failedTxnPresent := false - for _, h := range entry.Bid.TxHashes { - receipt, err := cluster.L1RPC().TransactionReceipt( - context.Background(), - common.HexToHash(h), + } else { + if pcmt.(*oracle.OracleCommitmentProcessed).IsSlash { + // check if any of the transactions were not successful, + // if so, the provider should not be slashed. Test doesnt + // handle reverting transactions. + failedTxnPresent := false + for _, h := range entry.Bid.TxHashes { + receipt, err := cluster.L1RPC().TransactionReceipt( + context.Background(), + common.HexToHash(h), + ) + if err != nil { + logger.Error( + "failed getting transaction receipt", + "error", err, + "entry", entry, + "hash", h, ) - if err != nil { - logger.Error( - "failed getting transaction receipt", - "error", err, - "entry", entry, - "hash", h, - ) - } - if receipt.Status != types.ReceiptStatusSuccessful { - failedTxnPresent = true - } } - if !failedTxnPresent { - logger.Error("Provider should not be slashed", "entry", entry) - return fmt.Errorf("provider should not be slashed") + if receipt.Status != types.ReceiptStatusSuccessful { + failedTxnPresent = true } - continue } - _, ok := store.Get(fundsRewardedKey(cmtDigest)) - if !ok { - logger.Error("Funds not rewarded", "entry", entry) - return fmt.Errorf("funds not rewarded") + if !failedTxnPresent { + logger.Error("Provider should not be slashed", "entry", entry) + return fmt.Errorf("provider should not be slashed") } + continue + } + _, ok := store.Get(fundsRewardedKey(cmtDigest)) + if !ok { + logger.Error("Funds not rewarded", "entry", entry) + return fmt.Errorf("funds not rewarded") } } } - if !foundCmt { - logger.Error( - "Winner not found in preconfs", - "entry", entry, - "winner", winner.(*blocktracker.BlocktrackerNewL1Block).Winner.Hex(), - ) - return fmt.Errorf("winner not found in preconfs") - } + } + if !foundCmt { + logger.Error( + "Winner not found in preconfs", + "entry", entry, + "winner", winner.(*blocktracker.BlocktrackerNewL1Block).Winner.Hex(), + ) + return fmt.Errorf("winner not found in preconfs") } }