-
Notifications
You must be signed in to change notification settings - Fork 226
/
consensus.go
89 lines (76 loc) · 2.44 KB
/
consensus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package types
import (
"database/sql"
"time"
)
type GenesisRow struct {
OneRowID bool `db:"one_row_id"`
ChainID string `db:"chain_id"`
Time time.Time `db:"time"`
InitialHeight int64 `db:"initial_height"`
}
func NewGenesisRow(chainID string, time time.Time, initialHeight int64) GenesisRow {
return GenesisRow{
OneRowID: true,
ChainID: chainID,
Time: time,
InitialHeight: initialHeight,
}
}
func (r GenesisRow) Equal(s GenesisRow) bool {
return r.Time.Equal(s.Time) &&
r.ChainID == s.ChainID &&
r.InitialHeight == s.InitialHeight
}
// -------------------------------------------------------------------------------------------------------------------
// ConsensusRow represents a single row inside the consensus table
type ConsensusRow struct {
Step string `db:"step"`
Height int64 `db:"height"`
Round int32 `db:"round"`
OneRowID bool `db:"one_row_id"`
}
// NewConsensusRow allows to build a new ConsensusRow instance
func NewConsensusRow(height int64, round int32, step string) ConsensusRow {
return ConsensusRow{
OneRowID: true,
Height: height,
Round: round,
Step: step,
}
}
// Equal tells whether r and s contain the same data
func (r ConsensusRow) Equal(s ConsensusRow) bool {
return r.Height == s.Height &&
r.Round == s.Round &&
r.Step == s.Step
}
// AverageTimeRow is the average block time each minute/hour/day
type AverageTimeRow struct {
OneRowID bool `db:"one_row_id"`
AverageTime float64 `db:"average_time"`
Height int64 `db:"height"`
}
func NewAverageTimeRow(averageTime float64, height int64) AverageTimeRow {
return AverageTimeRow{
OneRowID: true,
AverageTime: averageTime,
Height: height,
}
}
// Equal return true if two AverageTimeRow are true
func (r AverageTimeRow) Equal(s AverageTimeRow) bool {
return r.AverageTime == s.AverageTime &&
r.Height == s.Height
}
// -------------------------------------------------------------------------------------------------------------------
// BlockRow represents a single block row stored inside the database
type BlockRow struct {
Height int64 `db:"height"`
Hash string `db:"hash"`
TxNum int64 `db:"num_txs"`
TotalGas int64 `db:"total_gas"`
ProposerAddress sql.NullString `db:"proposer_address"`
PreCommitsNum int64 `db:"pre_commits"`
Timestamp time.Time `db:"timestamp"`
}