Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check types and fix tendermint #17

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deno Checks

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
deno-version: [1.35.3]

steps:
- name: Git Checkout Deno Module
uses: actions/checkout@v2
- name: Use Deno Version ${{ matrix.deno-version }}
uses: denolib/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}
- name: Check types
run: |
deno check main.ts
deno check *_test.ts
- name: Check formatting
run: deno fmt --check
2 changes: 2 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export { sha256 } from "npm:@cosmjs/crypto@^0.31.0";
export { toUtf8 } from "npm:@cosmjs/encoding@^0.31.0";
export { Decimal } from "npm:@cosmjs/math@^0.31.0";
export { DirectSecp256k1HdWallet } from "npm:@cosmjs/proto-signing@^0.31.0";
export { Tendermint34Client, Tendermint37Client } from "npm:@cosmjs/tendermint-rpc@^0.31.0";
export { assert, isDefined, sleep } from "npm:@cosmjs/utils@^0.31.0";
export type { Coin } from "npm:@cosmjs/amino@^0.31.0";
export type { MsgExecuteContractEncodeObject } from "npm:@cosmjs/cosmwasm-stargate@^0.31.0";
export type { SignerData } from "npm:@cosmjs/stargate@^0.31.0";
export type { TendermintClient } from "npm:@cosmjs/tendermint-rpc@^0.31.0";

// drand
export type { ChainClient, ChainOptions, RandomnessBeacon } from "npm:drand-client@^1.2.0";
Expand Down
5 changes: 4 additions & 1 deletion loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
RandomnessBeacon,
SignerData,
SigningCosmWasmClient,
TendermintClient,
} from "./deps.ts";
import { makeAddBeaconMessage } from "./drand_contract.ts";
import { ibcPacketsSent } from "./ibc.ts";

interface Capture {
client: SigningCosmWasmClient;
tmClient: TendermintClient;
broadcaster2: CosmWasmClient | null;
broadcaster3: CosmWasmClient | null;
botAddress: string;
Expand All @@ -29,6 +31,7 @@ interface Capture {
export async function loop(
{
client,
tmClient,
broadcaster2,
broadcaster3,
botAddress,
Expand Down Expand Up @@ -110,7 +113,7 @@ export async function loop(
`✔ #${beacon.round} committed (Points: ${points}; Payout: ${payout}; Gas: ${result.gasUsed}/${result.gasWanted}; Jobs processed: ${jobs}; Transaction: ${result.transactionHash})`,
);
const publishTime = timeOfRound(beacon.round) / 1000;
const { block } = await client.forceGetTmClient().block(result.height);
const { block } = await tmClient.block(result.height);
const commitTime = block.header.time.getTime() / 1000; // seconds with fractional part
const diff = commitTime - publishTime;
console.info(
Expand Down
5 changes: 4 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { BeaconCache } from "./cache.ts";
import { loop } from "./loop.ts";
import { queryIsAllowListed, queryIsIncentivized } from "./drand_contract.ts";
import { connectTendermint } from "./tendermint.ts";

// Constants
const gasLimitRegister = 200_000;
Expand Down Expand Up @@ -70,7 +71,8 @@ if (import.meta.main) {

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: config.prefix });
const [firstAccount] = await wallet.getAccounts();
const client = await SigningCosmWasmClient.connectWithSigner(config.rpcEndpoint, wallet, {
const tmClient = await connectTendermint(config.rpcEndpoint);
const client = await SigningCosmWasmClient.createWithSigner(tmClient, wallet, {
gasPrice: GasPrice.fromString(config.gasPrice),
});
const botAddress = firstAccount.address;
Expand Down Expand Up @@ -150,6 +152,7 @@ if (import.meta.main) {

const didSubmit = await loop({
client,
tmClient,
broadcaster2,
broadcaster3,
getNextSignData,
Expand Down
16 changes: 16 additions & 0 deletions tendermint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Tendermint34Client, Tendermint37Client, TendermintClient } from "./deps.ts";

export async function connectTendermint(endpoint: string): Promise<TendermintClient> {
// Tendermint/CometBFT 0.34/0.37 auto-detection. Starting with 0.37 we seem to get reliable versions again 🎉
// Using 0.34 as the fallback.
let tmClient: TendermintClient;
const tm37Client = await Tendermint37Client.connect(endpoint);
const version = (await tm37Client.status()).nodeInfo.version;
if (version.startsWith("0.37.")) {
tmClient = tm37Client;
} else {
tm37Client.disconnect();
tmClient = await Tendermint34Client.connect(endpoint);
}
return tmClient;
}
Loading