Skip to content

Commit 8cde9ac

Browse files
committed
add cli flag for health check
1 parent adadca9 commit 8cde9ac

17 files changed

+181
-95
lines changed

cmd/geth/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ func makeFullNode(ctx *cli.Context) *node.Node {
260260
v := ctx.Uint64(utils.OverrideHvm0.Name)
261261
cfg.Eth.OverrideHemiHvm0 = &v
262262
}
263+
if ctx.IsSet(utils.HealthDeucalionAddress.Name) {
264+
v := ctx.String(utils.HealthDeucalionAddress.Name)
265+
cfg.Eth.DeucalionAddress = v
266+
}
263267

264268
// TODO: expose debug.verbosityFlag or pass verbosity setting up the stack
265269
verbosity := ctx.Int("verbosity")

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ var (
173173
utils.TBCLevelDBHome,
174174
utils.TBCBlockSanity,
175175
utils.TBCNetwork,
176+
utils.HealthDeucalionAddress,
176177
utils.TBCPrometheusAddress,
177178
utils.OverrideHvmEnabled,
178179
utils.OverrideHvmGenesisHeader,

cmd/utils/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,12 @@ var (
10021002
Category: flags.RollupCategory,
10031003
Value: "", // No Prometheus by default
10041004
}
1005+
HealthDeucalionAddress = &cli.StringFlag{
1006+
Name: "hvm.deucalionaddress",
1007+
Usage: "Deucalion address for health checks",
1008+
Category: flags.RollupCategory,
1009+
Value: "", // No Deucalion by default
1010+
}
10051011
TBCSeeds = &cli.StringSliceFlag{
10061012
Name: "tbc.seeds",
10071013
Usage: "override tbc seeds when finding peers",

core/bench_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package core
1818

1919
import (
20+
"context"
2021
"crypto/ecdsa"
2122
"math/big"
2223
"testing"
@@ -200,7 +201,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
200201

201202
// Time the insertion of the new chain.
202203
// State and blocks are stored in the same DB.
203-
chainman, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil)
204+
chainman, _ := NewBlockChain(db, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, context.Background())
204205
defer chainman.Stop()
205206
b.ReportAllocs()
206207
b.ResetTimer()
@@ -338,7 +339,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
338339
}
339340
db = rawdb.NewDatabase(pdb)
340341

341-
chain, err := NewBlockChain(db, &cacheConfig, genesis, nil, ethash.NewFaker(), vm.Config{}, nil)
342+
chain, err := NewBlockChain(db, &cacheConfig, genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil, context.Background())
342343
if err != nil {
343344
b.Fatalf("error creating chain: %v", err)
344345
}

core/block_validator_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package core
1818

1919
import (
20+
"context"
2021
"math/big"
2122
"testing"
2223
"time"
@@ -50,7 +51,7 @@ func testHeaderVerification(t *testing.T, scheme string) {
5051
headers[i] = block.Header()
5152
}
5253
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
53-
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil)
54+
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, context.Background())
5455
defer chain.Stop()
5556

5657
for i := 0; i < len(blocks); i++ {
@@ -163,7 +164,7 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
163164
postHeaders[i] = block.Header()
164165
}
165166
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
166-
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil)
167+
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
167168
defer chain.Stop()
168169

169170
// Verify the blocks before the merging

core/blockchain.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ var (
129129

130130
emptyArray = [32]byte{}
131131

132+
// deucalion interval between progression check
133+
progressionInterval = 15 * time.Second
134+
132135
// Special error thrown when blockchain state manipulation functions find that the external header mode TBC
133136
// instance is in an impossible state implying data corruption or incrrect application of previous state trnsitions.
134137
ErrExternalHeaderTBCInvalidState = errors.New("external header TBC instance is in an invalid state")
@@ -326,6 +329,7 @@ type BlockChain struct {
326329
awaitingHvmSnapSync bool
327330
processingHvmSnapSync bool
328331
finishedHvmSnapSync bool
332+
healthyNode atomic.Bool
329333

330334
// Temporary workaround to allow restarting TBC Full Node when its not progressing
331335
fullBlockFailureCount uint32
@@ -560,36 +564,44 @@ func (bc *BlockChain) initHvmHeaderNode(config *tbc.Config) {
560564
bc.hvmEnabled = true
561565
}
562566

563-
const (
564-
progressionInterval = 15 * time.Second
565-
checkNumber = 3
566-
)
567-
568-
func (bc *BlockChain) SetupDeucalion(ctx context.Context) error {
567+
func (bc *BlockChain) SetupDeucalion(pctx context.Context, address string) error {
569568
d, err := deucalion.New(&deucalion.Config{
570-
ListenAddress: "localhost:8196",
569+
ListenAddress: address,
571570
})
572-
573571
if err != nil {
574572
return err
575573
}
576574

575+
ctx, cancel := context.WithCancel(pctx)
576+
577577
go func() {
578+
defer cancel()
578579
if err := d.Run(ctx, nil, func(ctx context.Context) (bool, any, error) {
579-
oldHeader := bc.CurrentHeader()
580-
for range checkNumber {
581-
time.Sleep(progressionInterval)
580+
return bc.healthyNode.Load(), bc.CurrentBlock(), nil
581+
}); !errors.Is(err, context.Canceled) {
582+
log.Error("deucalion terminated with error", "err", err)
583+
return
584+
}
585+
log.Info("deucalion clean shutdown")
586+
}()
587+
588+
go func() {
589+
defer cancel()
590+
oldHeader := bc.CurrentHeader()
591+
for {
592+
select {
593+
case <-ctx.Done():
594+
return
595+
case <-time.After(progressionInterval):
582596
curHeader := bc.CurrentHeader()
583597
if curHeader.Number.Cmp(oldHeader.Number) <= 0 {
584-
return false, nil, nil
598+
bc.healthyNode.Store(false)
599+
} else {
600+
bc.healthyNode.Store(true)
585601
}
602+
oldHeader = curHeader
586603
}
587-
return true, nil, nil
588-
}); !errors.Is(err, context.Canceled) {
589-
log.Error("prometheus terminated with error", "err", err)
590-
return
591604
}
592-
log.Info("prometheus clean shutdown")
593605
}()
594606

595607
return nil
@@ -2120,7 +2132,7 @@ func (bc *BlockChain) GetBitcoinAttributesForNextBlock(timestamp uint64) (*types
21202132
if len(headersToAdd) > 8 {
21212133
headersToAdd = headersToAdd[0:8]
21222134
}
2123-
log.Info(fmt.Sprintf("Headers to add while generating Bitcoin Attributes Deposited transaction: %d", headersToAdd))
2135+
log.Info(fmt.Sprintf("Headers to add while generating Bitcoin Attributes Deposited transaction: %v", headersToAdd))
21242136

21252137
// Walk up headersToAdd, and truncate blocks that TBC Full Node does not have complete information for
21262138
for i := 0; i < len(headersToAdd); i++ {
@@ -2698,7 +2710,7 @@ func (bc *BlockChain) updateHvmHeaderConsensus(newHead *types.Header, updateFull
26982710
if currentHead == nil {
26992711
log.Error(fmt.Sprintf("currentHead is nil, but should have been %x", currentHeadHash[:]))
27002712
} else {
2701-
log.Debug(fmt.Sprintf("Going to look for ancestor of %d @ %s and %d @ %s", newHead.Hash().String(),
2713+
log.Debug(fmt.Sprintf("Going to look for ancestor of %s @ %d and %s @ %d", newHead.Hash().String(),
27022714
newHead.Number.Uint64(), currentHead.Hash().String(), currentHead.Number.Uint64()))
27032715
}
27042716

core/blockchain_repair_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package core
2222

2323
import (
24+
"context"
2425
"math/big"
2526
"path/filepath"
2627
"testing"
@@ -1795,7 +1796,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
17951796
config.SnapshotLimit = 256
17961797
config.SnapshotWait = true
17971798
}
1798-
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil)
1799+
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
17991800
if err != nil {
18001801
t.Fatalf("Failed to create chain: %v", err)
18011802
}
@@ -1860,7 +1861,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
18601861
}
18611862
defer db.Close()
18621863

1863-
newChain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil)
1864+
newChain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
18641865
if err != nil {
18651866
t.Fatalf("Failed to recreate chain: %v", err)
18661867
}
@@ -1933,7 +1934,7 @@ func testIssue23496(t *testing.T, scheme string) {
19331934
}
19341935
engine = ethash.NewFullFaker()
19351936
)
1936-
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil)
1937+
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
19371938
if err != nil {
19381939
t.Fatalf("Failed to create chain: %v", err)
19391940
}
@@ -1983,7 +1984,7 @@ func testIssue23496(t *testing.T, scheme string) {
19831984
}
19841985
defer db.Close()
19851986

1986-
chain, err = NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil)
1987+
chain, err = NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
19871988
if err != nil {
19881989
t.Fatalf("Failed to recreate chain: %v", err)
19891990
}

core/blockchain_sethead_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package core
2121

2222
import (
23+
"context"
2324
"fmt"
2425
"math/big"
2526
"path/filepath"
@@ -1998,7 +1999,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
19981999
config.SnapshotLimit = 256
19992000
config.SnapshotWait = true
20002001
}
2001-
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil)
2002+
chain, err := NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
20022003
if err != nil {
20032004
t.Fatalf("Failed to create chain: %v", err)
20042005
}

core/blockchain_snapshot_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package core
2121

2222
import (
2323
"bytes"
24+
"context"
2425
"fmt"
2526
"math/big"
2627
"os"
@@ -82,7 +83,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
8283
}
8384
engine = ethash.NewFullFaker()
8485
)
85-
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(basic.scheme), gspec, nil, engine, vm.Config{}, nil)
86+
chain, err := NewBlockChain(db, DefaultCacheConfigWithScheme(basic.scheme), gspec, nil, engine, vm.Config{}, nil, nil, context.Background())
8687
if err != nil {
8788
t.Fatalf("Failed to create chain: %v", err)
8889
}
@@ -229,7 +230,7 @@ func (snaptest *snapshotTest) test(t *testing.T) {
229230

230231
// Restart the chain normally
231232
chain.Stop()
232-
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
233+
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
233234
if err != nil {
234235
t.Fatalf("Failed to recreate chain: %v", err)
235236
}
@@ -271,13 +272,13 @@ func (snaptest *crashSnapshotTest) test(t *testing.T) {
271272
// the crash, we do restart twice here: one after the crash and one
272273
// after the normal stop. It's used to ensure the broken snapshot
273274
// can be detected all the time.
274-
newchain, err := NewBlockChain(newdb, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
275+
newchain, err := NewBlockChain(newdb, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
275276
if err != nil {
276277
t.Fatalf("Failed to recreate chain: %v", err)
277278
}
278279
newchain.Stop()
279280

280-
newchain, err = NewBlockChain(newdb, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
281+
newchain, err = NewBlockChain(newdb, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
281282
if err != nil {
282283
t.Fatalf("Failed to recreate chain: %v", err)
283284
}
@@ -314,15 +315,15 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) {
314315
SnapshotLimit: 0,
315316
StateScheme: snaptest.scheme,
316317
}
317-
newchain, err := NewBlockChain(snaptest.db, cacheConfig, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
318+
newchain, err := NewBlockChain(snaptest.db, cacheConfig, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
318319
if err != nil {
319320
t.Fatalf("Failed to recreate chain: %v", err)
320321
}
321322
newchain.InsertChain(gappedBlocks)
322323
newchain.Stop()
323324

324325
// Restart the chain with enabling the snapshot
325-
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
326+
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
326327
if err != nil {
327328
t.Fatalf("Failed to recreate chain: %v", err)
328329
}
@@ -350,7 +351,7 @@ func (snaptest *setHeadSnapshotTest) test(t *testing.T) {
350351
chain.SetHead(snaptest.setHead)
351352
chain.Stop()
352353

353-
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
354+
newchain, err := NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
354355
if err != nil {
355356
t.Fatalf("Failed to recreate chain: %v", err)
356357
}
@@ -386,7 +387,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
386387
SnapshotLimit: 0,
387388
StateScheme: snaptest.scheme,
388389
}
389-
newchain, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
390+
newchain, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
390391
if err != nil {
391392
t.Fatalf("Failed to recreate chain: %v", err)
392393
}
@@ -403,7 +404,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
403404
SnapshotWait: false, // Don't wait rebuild
404405
StateScheme: snaptest.scheme,
405406
}
406-
tmp, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
407+
tmp, err := NewBlockChain(snaptest.db, config, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
407408
if err != nil {
408409
t.Fatalf("Failed to recreate chain: %v", err)
409410
}
@@ -412,7 +413,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
412413
tmp.triedb.Close()
413414
tmp.stopWithoutSaving()
414415

415-
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
416+
newchain, err = NewBlockChain(snaptest.db, DefaultCacheConfigWithScheme(snaptest.scheme), snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, context.Background())
416417
if err != nil {
417418
t.Fatalf("Failed to recreate chain: %v", err)
418419
}

0 commit comments

Comments
 (0)