Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e97d7dd
Initial HVM implementation for:
max-sanchez Mar 15, 2024
7df6192
Added hVM Methods:
max-sanchez Mar 25, 2024
1ff6996
Starting replacement of temp indexer with TBC
max-sanchez Apr 5, 2024
c1bb4d2
Add excludes to resolve dependency conflicts
max-sanchez Apr 7, 2024
a676dc7
Fix dependency build issues
max-sanchez Apr 7, 2024
84a0dc5
Updated TBC integration
max-sanchez Apr 8, 2024
2536aae
Updated all remaining methods to use TBC except txConfirmations
max-sanchez Apr 8, 2024
c590ab6
Update btcTxConfirmations method
max-sanchez Apr 8, 2024
45dcd64
Fix indexing logic if indexed height is greater than supplied tip
max-sanchez Apr 8, 2024
24efdf6
Misc cleanup
max-sanchez Apr 8, 2024
aec55ed
Misc cleanup
max-sanchez Apr 8, 2024
38aefae
Update init index height logging
max-sanchez Apr 8, 2024
21815ef
Update indexing logic on first startup
max-sanchez Apr 8, 2024
74f8532
Init status for TBC indexing
max-sanchez Apr 9, 2024
5171d24
Run TBC init before other services are started up
max-sanchez Apr 9, 2024
12eac72
Pass context block hash to precompile calls
max-sanchez Apr 9, 2024
a0de844
Separate headerHash context for EVM execution
max-sanchez Apr 9, 2024
804f7c6
TBC Progression
max-sanchez Apr 10, 2024
83bea42
Fixes
max-sanchez Apr 10, 2024
05996a3
Hooked up caching of hVM query responses
max-sanchez Apr 10, 2024
793834d
Fix map
max-sanchez Apr 10, 2024
a323391
Fix
max-sanchez Apr 10, 2024
265b2b3
Fix contract mapping
max-sanchez Apr 10, 2024
93518d6
Update init height for testing
max-sanchez Apr 10, 2024
539abe8
Only check/fill hVMQueryCache if containing block is not null block
max-sanchez Apr 10, 2024
d51be97
Only check existing blocks to initHeight on firstStartup
max-sanchez Apr 10, 2024
75989f5
Hookup new TBC SyncIndexersToHeight() method
max-sanchez Apr 10, 2024
2f58882
Fix bit shift
max-sanchez Apr 16, 2024
61a7a86
Update heminetwork path to ../optimism/
max-sanchez Apr 16, 2024
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
98 changes: 98 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package main

import (
"encoding/binary"
"fmt"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/hemilabs/heminetwork/service/tbc"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -154,6 +157,12 @@ var (
utils.RollupComputePendingBlock,
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
utils.RollupSuperchainUpgradesFlag,
utils.TBCListenAddress,
utils.TBCMaxCachedTxs,
utils.TBCLevelDBHome,
utils.TBCBlockSanity,
utils.TBCNetwork,
utils.TBCPrometheusAddress,
configFileFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)

Expand Down Expand Up @@ -373,6 +382,95 @@ func geth(ctx *cli.Context) error {
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isConsole bool) {
// Before starting up any other services, make sure TBC is in correct initial state
tbcCfg := tbc.NewDefaultConfig()

// TODO: Pull from chain config, each Hemi chain should be configured with a corresponding BTC net
tbcCfg.Network = "testnet3"

if ctx.IsSet(utils.TBCListenAddress.Name) {
tbcCfg.ListenAddress = ctx.String(utils.TBCListenAddress.Name)
}
if ctx.IsSet(utils.TBCMaxCachedTxs.Name) {
tbcCfg.MaxCachedTxs = ctx.Int(utils.TBCMaxCachedTxs.Name)
}
if ctx.IsSet(utils.TBCLevelDBHome.Name) {
tbcCfg.LevelDBHome = ctx.String(utils.TBCLevelDBHome.Name)
}
if ctx.IsSet(utils.TBCBlockSanity.Name) {
tbcCfg.BlockSanity = ctx.Bool(utils.TBCBlockSanity.Name)
}
if ctx.IsSet(utils.TBCNetwork.Name) {
tbcCfg.Network = ctx.String(utils.TBCNetwork.Name)
}
if ctx.IsSet(utils.TBCPrometheusAddress.Name) {
tbcCfg.PrometheusListenAddress = ctx.String(utils.TBCPrometheusAddress.Name)
}
// TODO: convert op-geth log level integer to TBC log level string

// Initialize TBC Bitcoin indexer to answer hVM queries
err := vm.SetupTBC(ctx.Context, tbcCfg)

// TODO: Review, give TBC time to warm up
time.Sleep(5 * time.Second)

firstStartup := false

utxoHeight, err := vm.TBCIndexer.DB().MetadataGet(ctx.Context, tbc.UtxoIndexHeightKey)
if err != nil {
log.Info("Unable to get UTXO height key from database, assuming first startup.")
firstStartup = true
}

txHeight, err := vm.TBCIndexer.DB().MetadataGet(ctx.Context, tbc.TxIndexHeightKey)
if err != nil {
log.Info("Unable to get Tx height key from database, assuming first startup.")
firstStartup = true
}

if !firstStartup {
log.Info("On op-geth startup, TBC index status: ", "utxoIndexHeight",
binary.BigEndian.Uint64(utxoHeight), "txIndexHeight", binary.BigEndian.Uint64(txHeight))
}

var initHeight uint64
initHeight = 2585811 // Temp for testing, this should be part of chain config

if firstStartup {
for {
log.Info(fmt.Sprintf("TBC has not downloaded the BTC chain up to %d yet."+
" Cannot progress Hemi chain until download is complete.", initHeight))
time.Sleep(5 * time.Second)
if vm.TBCBlocksAvailableToHeight(ctx.Context, 0, initHeight) {
log.Info("TBC Initial syncing is complete, continuing...")
break
} else {
log.Info("Geth still waiting for TBC initial sync", "initHeight", initHeight)
}
}

err = vm.TBCIndexer.SyncIndexersToHeight(ctx.Context, initHeight)

log.Info("Finished initial indexing", "initHeight", initHeight)
}

si := vm.TBCIndexer.Synced(ctx.Context)

if si.UtxoHeight < initHeight {
log.Crit("TBC did not index UTXOs to initHeight!",
"utxoIndexHeight", si.UtxoHeight, "initHeight", initHeight)
}

if si.TxHeight < initHeight {
log.Crit("TBC did not index txs to initHeight!",
"txIndexHeight", si.TxHeight, "initHeight", initHeight)
}

log.Info("TBC initial sync completed", "headerHeight", si.BlockHeaderHeight,
"utxoIndexHeight", si.UtxoHeight, "txIndexHeight", si.TxHeight)

vm.SetInitReady()

debug.Memsize.Add("node", stack)

// Start up the node itself
Expand Down
36 changes: 36 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,42 @@ var (
Category: flags.RollupCategory,
Value: true,
}
TBCListenAddress = &cli.StringFlag{
Name: "tbc.listenaddress",
Usage: "Address for TBC daemon to listen on",
Category: flags.RollupCategory,
Value: "127.0.0.1",
}
TBCMaxCachedTxs = &cli.IntFlag{
Name: "tbc.maxcachedtxs",
Usage: "Max number of transactions TBC will cache before flushing to disk",
Category: flags.RollupCategory,
Value: 1e6, // max key 69, max value 36
}
TBCLevelDBHome = &cli.StringFlag{
Name: "tbc.leveldbhome",
Usage: "Directory for TBC's LevelDB database",
Category: flags.RollupCategory,
Value: "~/.tbcd", // TODO: Review default value here
}
TBCBlockSanity = &cli.BoolFlag{
Name: "tbc.blocksanity",
Usage: "Enable/disable block sanity checks before inserting",
Category: flags.RollupCategory,
Value: false,
}
TBCNetwork = &cli.StringFlag{
Name: "tbc.network",
Usage: "Bitcoin network TBC is running on",
Category: flags.RollupCategory,
Value: "testnet3", // Change default to mainnet on Hemi mainnet
}
TBCPrometheusAddress = &cli.StringFlag{
Name: "tbc.prometheusaddress",
Usage: "Prometheus address for TBC metric monitoring",
Category: flags.RollupCategory,
Value: "", // No Prometheus by default
}

// Metrics flags
MetricsEnabledFlag = &cli.BoolFlag{
Expand Down
3 changes: 3 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package core

import (
context2 "context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -2369,6 +2370,8 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) {
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
}
log.Info("Chain head was updated", context...)
vm.ProgressTip(context2.Background(), uint32(head.Time()))

return head.Hash(), nil
}

Expand Down
12 changes: 12 additions & 0 deletions core/hvm/dbobj.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hvm

type output struct {
txid []byte
index uint32
value uint64
spendScript []byte
address string
scriptsig []byte
spent bool
spendtx []byte
}
Loading