-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I used this tool to predict the arrival time of the v2 activation height on Mocha.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Block ETA (Estimated Time of Arrival) | ||
|
||
blocketa is a tool that estimates the time of arrival of a block height. | ||
|
||
## Usage | ||
|
||
```shell | ||
$ go run main.go https://celestia-mocha-rpc.publicnode.com:443 2585031 | ||
chainID: mocha-4 | ||
currentHeight: 2580660 | ||
currentTime: 2024-08-28 02:46:32.933542677 +0000 UTC | ||
diffInBlockHeight: 4371 | ||
diffInTime: 14h37m50.55s | ||
arrivalTime: 2024-08-28 17:24:23.483542677 +0000 UTC | ||
``` | ||
|
||
> [!NOTE] | ||
> The block time is currently hard-coded. If you're running this for a network with a different block time, you'll need to update the `blockTime` constant in the main.go file. You can use https://www.mintscan.io/celestia/block/ or the blocktime tool. |
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,81 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/tendermint/tendermint/rpc/client/http" | ||
) | ||
|
||
const ( | ||
// blockTime is the observed average time between blocks. You can update this | ||
// value based on the block time on https://www.mintscan.io/celestia/block/ or | ||
// the output from the blocktime tool. | ||
blockTime = 12.05 // seconds between blocks for Mocha | ||
|
||
// exampleArabicaRPC is an example node RPC endpoint for the Arabica testnet. | ||
exampleArabicaRPC = "https://rpc.celestia-arabica-11.com:443" | ||
|
||
// exampleMochaRPC is an example node RPC endpoint for the Mocha testnet. | ||
exampleMochaRPC = "https://celestia-mocha-rpc.publicnode.com:443" | ||
|
||
// exampleArabicaHeight is an example block height for the Arabica testnet. | ||
exampleArabicaHeight = 1751707 | ||
|
||
// exampleMochaHeight is an example block height for the Mocha testnet. | ||
exampleMochaHeight = 2585031 | ||
) | ||
|
||
func main() { | ||
if err := Run(); err != nil { | ||
fmt.Printf("ERROR: %s", err.Error()) | ||
} | ||
} | ||
|
||
func Run() error { | ||
if len(os.Args) < 3 { | ||
fmt.Printf("Usage: %s <node_rpc> <target_block_height>\n", os.Args[0]) | ||
fmt.Printf("Example: %s %s %v\n", os.Args[0], exampleArabicaRPC, exampleArabicaHeight) | ||
fmt.Printf("Example: %s %s %v\n", os.Args[0], exampleMochaRPC, exampleMochaHeight) | ||
return nil | ||
} | ||
|
||
_, nodeRPC, targetBlockHeightArg := os.Args[0], os.Args[1], os.Args[2] | ||
targetBlockHeight, err := strconv.ParseInt(targetBlockHeightArg, 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
c, err := http.New(nodeRPC, "/websocket") | ||
if err != nil { | ||
return err | ||
} | ||
resp, err := c.Status(context.Background()) | ||
if err != nil { | ||
return err | ||
} | ||
chainID := resp.NodeInfo.Network | ||
currentHeight := resp.SyncInfo.LatestBlockHeight | ||
currentTime := resp.SyncInfo.LatestBlockTime | ||
|
||
if currentHeight >= targetBlockHeight { | ||
return fmt.Errorf("current height %v is already after target height %v", currentHeight, targetBlockHeight) | ||
} | ||
diffInBlockHeight := targetBlockHeight - currentHeight | ||
diffInSeconds := blockTime * float64(diffInBlockHeight) | ||
diffInTime, err := time.ParseDuration(fmt.Sprintf("%vs", diffInSeconds)) | ||
if err != nil { | ||
return err | ||
} | ||
arrivalTime := currentTime.Add(diffInTime) | ||
|
||
fmt.Printf("chainID: %v\n", chainID) | ||
fmt.Printf("currentHeight: %v\n", currentHeight) | ||
fmt.Printf("currentTime: %v\n", currentTime.String()) | ||
fmt.Printf("diffInBlockHeight: %v\n", diffInBlockHeight) | ||
fmt.Printf("diffInTime: %v\n", diffInTime) | ||
fmt.Printf("arrivalTime: %v\n", arrivalTime) | ||
return nil | ||
} |