-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e consensus test (#3126)
* test: add e2e consensus test * move to merge queue * fix * add e2e block production monitor
- Loading branch information
Showing
5 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package local | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | ||
cometbft_types "github.com/cometbft/cometbft/types" | ||
|
||
"github.com/zeta-chain/node/e2e/config" | ||
) | ||
|
||
// monitorBlockProductionExit calls monitorBlockProduction and exits upon any error | ||
func monitorBlockProductionExit(ctx context.Context, conf config.Config) { | ||
err := monitorBlockProduction(ctx, conf) | ||
if err != nil { | ||
fmt.Printf("❌ block monitor: %v\n", err) | ||
os.Exit(2) | ||
} | ||
} | ||
|
||
// monitorBlockProduction subscribes to new block events to monitor if blocks are being produced | ||
// at least every four seconds | ||
func monitorBlockProduction(ctx context.Context, conf config.Config) error { | ||
rpcClient, err := rpchttp.New(conf.RPCs.ZetaCoreRPC, "/websocket") | ||
if err != nil { | ||
return fmt.Errorf("new zetacore rpc: %w", err) | ||
} | ||
|
||
err = rpcClient.WSEvents.Start() | ||
if err != nil { | ||
return fmt.Errorf("start ws events: %w", err) | ||
} | ||
blockEventChan, err := rpcClient.WSEvents.Subscribe(ctx, "", "tm.event='NewBlock'") | ||
if err != nil { | ||
return fmt.Errorf("subscribe: %w", err) | ||
} | ||
latestNewBlockEvent := cometbft_types.EventDataNewBlock{} | ||
for { | ||
select { | ||
case event := <-blockEventChan: | ||
newBlockEvent, ok := event.Data.(cometbft_types.EventDataNewBlock) | ||
if !ok { | ||
return fmt.Errorf("expecting new block event, got %T", event.Data) | ||
} | ||
latestNewBlockEvent = newBlockEvent | ||
case <-time.After(4 * time.Second): | ||
return fmt.Errorf("timed out waiting for new block (last block %d)", latestNewBlockEvent.Block.Height) | ||
case <-ctx.Done(): | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters