Skip to content

Commit 73cb486

Browse files
authored
move asciiart to node (#1276)
1 parent 8343809 commit 73cb486

5 files changed

Lines changed: 133 additions & 149 deletions

File tree

builtin/staker/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *Staker) SyncPOS(forkConfig *thor.ForkConfig, current uint32) (Status, e
3737
}
3838

3939
// attempt to transition if we're on a transition block and the staker contract is not active
40-
if !status.Active && (forkConfig.HAYABUSA_TP == 0 || current%forkConfig.HAYABUSA_TP == 0) {
40+
if !status.Active && (forkConfig.HAYABUSA_TP == 0 || (current-forkConfig.HAYABUSA)%forkConfig.HAYABUSA_TP == 0) {
4141
activated, err = s.transition(current)
4242
if err != nil {
4343
return status, fmt.Errorf("failed to transition to dPoS: %w", err)

cmd/thor/node/ascii_art.go

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,77 @@ import (
1010
"strings"
1111
)
1212

13-
const GalacticaASCIIArt = `
14-
/\ /\
15-
/ \---._
16-
/ / ` + "`" + ` ` + "`" + `\
17-
\ \ <@)@)
18-
/` + "`" + ` ~ ~._
19-
/ ` + "`" + `()
20-
/ \ /
21-
/ |` + "`" + `\_ /
22-
___/________|_ ` + "`" + `—____/
23-
(______________)
24-
_/~ |
25-
_/~ \
26-
_/~ |
27-
_/~ |
28-
_/~ |
29-
_/~ ~. |
30-
_/~ \ /\
31-
__/~ /` + "`" + `\ ` + "`" + `||
32-
_/~ ~~-._ /~ \ ||
33-
/~ ~./~' \ |)
34-
/ ~. \ )|
35-
/ : | ||
36-
| : | ||
37-
| .' | ||
38-
__.-` + "`" + ` __.'--. | |` + "`" + `---.
39-
.-~ ___. __.--~` + "`" + `--.)))) | ` + "`" + `---.)))
40-
` + "`" + `---~~ ` + "`" + `-...--.________))))) \_____)))))
41-
42-
43-
______ _ _____ _ ______ _________ _____ ______ _
44-
.' ___ | / \ |_ _| / \ .' ___ || _ _ ||_ _|.' ___ | / \
45-
/ .' \_| / _ \ | | / _ \ / .' \_||_/ | | \_| | | / .' \_| / _ \
46-
| | ____ / ___ \ | | _ / ___ \ | | | | | | | | / ___ \
47-
\ ` + "`" + `.___] |_/ / \ \_ _| |__/ | _/ / \ \_\ ` + "`" + `.___.'\ _| |_ _| |_\ ` + "`" + `.___.'\ _/ / \ \_
48-
` + "`" + `._____.'|____| |____||________||____| |____|` + "`" + `.____ .' |_____| |_____|` + "`" + `.____ .'|____| |____|
13+
const HayabusaASCIIArt = `
14+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
15+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀
16+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢠⠀⠀⠀⠀⢸⣇⠀⠀⠀⠀⠀⠀⣰⣿⣿⠀⠀⣼⣧⠀⠀⠀⠀⠀⠀
17+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣿⡀⠀⠀⠀⣸⣿⠀⣸⡀⠀⠀⢠⣿⣿⣿⠀⣸⣿⣿⠀⠀⠀⠀⠀⠀
18+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠀⣿⣿⣇⣿⡇⠀⠀⣾⣿⣿⡏⢰⣿⣿⣿⠀⠀⠀⠀⠀⠀
19+
⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⣿⣿⣧⠀⢸⣿⣿⣿⣿⡇⠀⣸⣿⣿⣿⢁⣿⣿⣿⡟⠀⣰⡇⠀⠀⠀
20+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣦⣿⣿⣿⣿⣿⡇⣰⣿⣿⣿⣏⣾⣿⣿⣿⠃⣼⣿⡇⠀⠀⠀
21+
⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⠟⣰⣿⣿⣿⣿⣿⣿⣿⣿⠏⣼⣿⣿⠁⠀⠀⠀
22+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⡿⢁⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⠇⠀⠀⠀⠀
23+
⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠸⣿⣿⣿⡿⠋⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢋⣴⡾⠀⠀⠀
24+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀ ⠀⠀⠀⣿⣿⠋⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣵⣿⣿⠇⠀⠀⠀
25+
⠀⠀ ⠀⠀ ⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠛⣡⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀
26+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣤⠀⠀⠀⠀
27+
⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀ ⠀⡄⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⡟⠀⠀⠀⠀
28+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡆⣾⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀
29+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡇⠀⠀⠀⠀
30+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀
31+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⠀⠀⠀⠀⠀
32+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⣶⡏⠀⠀⠀⠀⠀
33+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀
34+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀
35+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀
36+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
37+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
38+
⠀⠀⠀⢀⣠⣤⣤⣶⣶⣦⣤⣤⣀⣀⡀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
39+
⠀⠀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
40+
⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣁⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
41+
⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
42+
⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
43+
⢼⣿⣿⣿⠟⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
44+
⠘⢿⡿⠁⠀⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⢀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
45+
⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣶⣶⡤⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
46+
⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣦⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀
47+
⠀⠀⠀⠀⠀⠀⠀⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⠿⠷⠶⠄⠀⠀⠀
48+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣦⣄⣀⠀⠀⠀⠀⠀
49+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⡀⠀
50+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⡿⢿⣿⣿⣦
51+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠈⠉⠛⠿⢿⣿⣿⣟⠿⢿⣿⣿⡿⢿⣿⣿⣿⣿⣽⡛⠿⣿⣿⣷⣄⠀⠀⠀
52+
⠀⠀⠀⣀⣀⠀⠀⠀⠀⢶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠷⣄⠀⠉⠙⠀⠀⠉⠙⠛⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀
53+
⠀⢠⣿⣿⣿⣿⣦⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
54+
⠀⠘⠉⣿⠿⠉⢹⣿⡏⠁⠘⣻⣿⣿⣿⣿⣿⡿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
55+
⠀⠀⠀⠈⠀⢛⣿⣟⡀⣠⣾⣿⣿⠟⠿⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
56+
⠀⠀⠀⢠⣾⠿⢿⣿⣿⣿⣿⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
57+
⠀⠀⠀⠸⠋⣾⣿⠋⠀⠈⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
58+
⠀⠀⠀⠀⠀⠘⠃⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
59+
____ ____ _ ____ ____ _ ______ _____ _____ ______ _
60+
|_ || _| / \ |_ _| |_ _| / \ |_ _ \ |_ _||_ _|.' ____ \ / \
61+
| |__| | / _ \ \ \ / / / _ \ | |_) | | | | | | (___ \_| / _ \
62+
| __ | / ___ \ \ \/ / / ___ \ | __'. | ' ' | _.____` + "`" + `. / ___ \
63+
_| | | |_ _/ / \ \_ _| |_ / / \ \_ _| |__) | \ \__ / / | \____) | _/ / \ \_
64+
|____||____||____| |____||______||____| |____||_______/ ` + "`" + `.__.' \______.'|____| |____|
4965
_ ______ _________ _____ ____ ____ _ _________ ________ ______
5066
/ \ .' ___ || _ _ ||_ _||_ _| |_ _|/ \ | _ _ ||_ __ ||_ _ ` + "`" + `
5167
/ _ \ / .' \_||_/ | | \_| | | \ \ / / / _ \ |_/ | | \_| | |_ \_| | | ` + "`" + `. \
5268
/ ___ \ | | | | | | \ \ / / / ___ \ | | | _| _ | | | |
5369
_/ / \ \_\ ` + "`" + `.___.'\ _| |_ _| |_ \ ' /_/ / \ \_ _| |_ _| |__/ | _| |_.' /
54-
|____| |____|` + "`" + `.____ .' |_____| |_____| \_/|____| |____||_____| |________||______.'
55-
`
70+
|____| |____|` + "`" + `.____ .' |_____| |_____| \_/|____| |____||_____| |________||______.'`
5671

5772
var printed bool
5873

59-
func printGalacticaWelcomeInfo() {
60-
if !printed {
61-
// remove the leading new line symbol as previous printed log will have a new line symbol
62-
str, _ := strings.CutPrefix(GalacticaASCIIArt, "\n")
63-
os.Stdout.WriteString(str)
64-
printed = true
74+
func printWelcomeInfo() {
75+
if printed {
76+
return
6577
}
78+
printed = true
79+
// remove the leading new line symbol as previous printed log will have a new line symbol
80+
str, _ := strings.CutPrefix(HayabusaASCIIArt, "\n")
81+
os.Stdout.WriteString(str)
82+
}
83+
84+
func needPrintWelcomeInfo() bool {
85+
return !printed
6686
}

cmd/thor/node/node.go

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

316347
func (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

Comments
 (0)