@@ -21,6 +21,7 @@ import (
2121
2222 "github.com/vechain/thor/v2/bft"
2323 "github.com/vechain/thor/v2/block"
24+ "github.com/vechain/thor/v2/builtin"
2425 "github.com/vechain/thor/v2/cache"
2526 "github.com/vechain/thor/v2/chain"
2627 "github.com/vechain/thor/v2/cmd/thor/bandwidth"
@@ -59,6 +60,7 @@ type Node struct {
5960 master * Master
6061 repo * chain.Repository
6162 bft * bft.Engine
63+ stater * state.Stater
6264 logDB * logdb.LogDB
6365 txPool * txpool.TxPool
6466 txStashPath string
@@ -92,6 +94,7 @@ func New(
9294 master : master ,
9395 repo : repo ,
9496 bft : bft ,
97+ stater : stater ,
9598 logDB : logDB ,
9699 txPool : txPool ,
97100 txStashPath : txStashPath ,
@@ -279,17 +282,14 @@ func (n *Node) txStashLoop(ctx context.Context) {
279282}
280283
281284// guardBlockProcessing adds lock on block processing and maintains block conflicts.
282- func (n * Node ) guardBlockProcessing (blockNum uint32 , process func (conflicts [][]byte ) error ) ( err error ) {
285+ func (n * Node ) guardBlockProcessing (blockNum uint32 , process func (conflicts [][]byte ) (thor. Bytes32 , error )) error {
283286 n .processLock .Lock ()
284- defer func () {
285- // post process block hook, executed only if the block is processed successfully
286- if err == nil {
287- if n .initialSynced && blockNum == n .forkConfig .GALACTICA {
288- printGalacticaWelcomeInfo ()
289- }
290- }
291- n .processLock .Unlock ()
292- }()
287+ defer n .processLock .Unlock ()
288+
289+ var (
290+ err error
291+ blockID thor.Bytes32
292+ )
293293
294294 if blockNum > n .maxBlockNum {
295295 if blockNum > n .maxBlockNum + 1 {
@@ -298,7 +298,7 @@ func (n *Node) guardBlockProcessing(blockNum uint32, process func(conflicts [][]
298298 }
299299
300300 // don't increase maxBlockNum if the block is unprocessable
301- if err : = process (make ([][]byte , 0 )); err != nil {
301+ if blockID , err = process (make ([][]byte , 0 )); err != nil {
302302 return err
303303 }
304304
@@ -310,30 +310,61 @@ func (n *Node) guardBlockProcessing(blockNum uint32, process func(conflicts [][]
310310 if err != nil {
311311 return err
312312 }
313- return process (conflicts )
313+ blockID , err = process (conflicts )
314+ if err != nil {
315+ return err
316+ }
317+
318+ // post process block hook, executed only if the block is processed successfully
319+ if err = func () error {
320+ if n .initialSynced {
321+ if needPrintWelcomeInfo () &&
322+ blockNum >= n .forkConfig .HAYABUSA + n .forkConfig .HAYABUSA_TP &&
323+ // if transition period are set to 0, transition will attempt to happen on every block
324+ (n .forkConfig .HAYABUSA_TP == 0 || (blockNum - n .forkConfig .HAYABUSA )% n .forkConfig .HAYABUSA_TP == 0 ) {
325+ summary , err := n .repo .GetBlockSummary (blockID )
326+ if err != nil {
327+ return err
328+ }
329+ state := n .stater .NewState (summary .Root ())
330+ active , err := builtin .Staker .Native (state ).IsPoSActive ()
331+ if err != nil {
332+ return nil
333+ }
334+ if active {
335+ printWelcomeInfo ()
336+ }
337+ }
338+ }
339+ return nil
340+ }(); err != nil {
341+ logger .Warn ("failed to run post process hook" , "err" , err )
342+ }
343+
344+ return nil
314345}
315346
316347func (n * Node ) processBlock (newBlock * block.Block , stats * blockStats ) (bool , error ) {
317348 var isTrunk * bool
318349
319- if err := n .guardBlockProcessing (newBlock .Header ().Number (), func (conflicts [][]byte ) error {
350+ if err := n .guardBlockProcessing (newBlock .Header ().Number (), func (conflicts [][]byte ) (thor. Bytes32 , error ) {
320351 // Check whether the block was already there.
321352 // It can be skipped if no conflicts.
322353 if len (conflicts ) > 0 {
323354 newSigner , err := newBlock .Header ().Signer ()
324355 if err != nil {
325- return err
356+ return thor. Bytes32 {}, err
326357 }
327358 // iter over conflicting blocks
328359 for _ , conflict := range conflicts {
329360 conflictBlock , err := n .repo .GetBlock (thor .BytesToBytes32 (conflict ))
330361 if err != nil {
331- return err
362+ return thor. Bytes32 {}, err
332363 }
333364 // logic to verify that the blocks are different and from the same signer
334365 signer , err := conflictBlock .Header ().Signer ()
335366 if err != nil {
336- return err
367+ return thor. Bytes32 {}, err
337368 }
338369 if signer == newSigner &&
339370 conflictBlock .Header ().ID () != newBlock .Header ().ID () &&
@@ -346,18 +377,18 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
346377 _ , err = n .repo .GetBlockSummary (newBlock .Header ().ID ())
347378 if err != nil {
348379 if ! n .repo .IsNotFound (err ) {
349- return err
380+ return thor. Bytes32 {}, err
350381 }
351382 } else {
352- return errKnownBlock
383+ return thor. Bytes32 {}, errKnownBlock
353384 }
354385 }
355386 parentSummary , err := n .repo .GetBlockSummary (newBlock .Header ().ParentID ())
356387 if err != nil {
357388 if ! n .repo .IsNotFound (err ) {
358- return err
389+ return thor. Bytes32 {}, err
359390 }
360- return errParentMissing
391+ return thor. Bytes32 {}, errParentMissing
361392 }
362393
363394 var (
@@ -366,23 +397,23 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
366397 )
367398
368399 if ok , err := n .bft .Accepts (newBlock .Header ().ParentID ()); err != nil {
369- return errors .Wrap (err , "bft accepts" )
400+ return thor. Bytes32 {}, errors .Wrap (err , "bft accepts" )
370401 } else if ! ok {
371- return errBFTRejected
402+ return thor. Bytes32 {}, errBFTRejected
372403 }
373404
374405 // process the new block
375406 stage , receipts , err := n .cons .Process (parentSummary , newBlock , uint64 (time .Now ().Unix ()), uint32 (len (conflicts )))
376407 if err != nil {
377- return err
408+ return thor. Bytes32 {}, err
378409 }
379410
380411 var becomeNewBest bool
381412 // let bft engine decide the best block after fork FINALITY
382413 if newBlock .Header ().Number () >= n .forkConfig .FINALITY && oldBest .Header .Number () >= n .forkConfig .FINALITY {
383414 becomeNewBest , err = n .bft .Select (newBlock .Header ())
384415 if err != nil {
385- return errors .Wrap (err , "bft select" )
416+ return thor. Bytes32 {}, errors .Wrap (err , "bft select" )
386417 }
387418 } else {
388419 becomeNewBest = newBlock .Header ().BetterThan (oldBest .Header )
@@ -395,13 +426,13 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
395426 // write logs
396427 if logEnabled {
397428 if err := n .writeLogs (newBlock , receipts , oldBest .Header .ID ()); err != nil {
398- return errors .Wrap (err , "write logs" )
429+ return thor. Bytes32 {}, errors .Wrap (err , "write logs" )
399430 }
400431 }
401432
402433 // commit produced states
403434 if _ , err := stage .Commit (); err != nil {
404- return errors .Wrap (err , "commit state" )
435+ return thor. Bytes32 {}, errors .Wrap (err , "commit state" )
405436 }
406437
407438 // sync the log-writing task
@@ -414,13 +445,13 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
414445
415446 // add the new block into repository
416447 if err := n .repo .AddBlock (newBlock , receipts , uint32 (len (conflicts )), becomeNewBest ); err != nil {
417- return errors .Wrap (err , "add block" )
448+ return thor. Bytes32 {}, errors .Wrap (err , "add block" )
418449 }
419450
420451 // commit block in bft engine
421452 if newBlock .Header ().Number () >= n .forkConfig .FINALITY {
422453 if err := n .bft .CommitBlock (newBlock .Header (), false ); err != nil {
423- return errors .Wrap (err , "bft commits" )
454+ return thor. Bytes32 {}, errors .Wrap (err , "bft commits" )
424455 }
425456 }
426457
@@ -440,7 +471,7 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
440471 metricBlockProcessedTxs ().SetWithLabel (int64 (len (receipts )), map [string ]string {"type" : "received" })
441472 metricBlockProcessedGas ().SetWithLabel (int64 (newBlock .Header ().GasUsed ()), map [string ]string {"type" : "received" })
442473 metricBlockProcessedDuration ().Observe (time .Duration (realElapsed ).Milliseconds ())
443- return nil
474+ return newBlock . Header (). ID (), nil
444475 }); err != nil {
445476 switch {
446477 case err == errKnownBlock :
0 commit comments