-
Notifications
You must be signed in to change notification settings - Fork 95
/
consensus.go
67 lines (57 loc) · 1.58 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
package consensus
import (
"time"
"github.com/vitelabs/go-vite/common/types"
"github.com/vitelabs/go-vite/consensus/core"
"github.com/vitelabs/go-vite/ledger"
)
type Verifier interface {
VerifyAccountProducer(block *ledger.AccountBlock) (bool, error)
VerifySnapshotProducer(block *ledger.SnapshotBlock) (bool, error)
}
type Event struct {
Gid types.Gid
Address types.Address
Stime time.Time
Etime time.Time
Timestamp time.Time // add to block
SnapshotHash types.Hash // add to block
SnapshotHeight uint64 // add to block
}
type electionResult struct {
Plans []*core.MemberPlan
STime time.Time
ETime time.Time
Index uint64
Hash types.Hash
Height uint64
}
type ProducersEvent struct {
Addrs []types.Address
Index uint64
Gid types.Gid
}
type Subscriber interface {
Subscribe(gid types.Gid, id string, addr *types.Address, fn func(Event))
UnSubscribe(gid types.Gid, id string)
SubscribeProducers(gid types.Gid, id string, fn func(event ProducersEvent))
}
type Reader interface {
ReadByIndex(gid types.Gid, index uint64) ([]*Event, uint64, error)
ReadByTime(gid types.Gid, t time.Time) ([]*Event, uint64, error)
ReadVoteMapByTime(gid types.Gid, index uint64) ([]*VoteDetails, *ledger.HashHeight, error)
ReadVoteMapForAPI(gid types.Gid, t time.Time) ([]*VoteDetails, *ledger.HashHeight, error)
VoteTimeToIndex(gid types.Gid, t2 time.Time) (uint64, error)
VoteIndexToTime(gid types.Gid, i uint64) (*time.Time, *time.Time, error)
}
type Life interface {
Start()
Init() error
Stop()
}
type Consensus interface {
Verifier
Subscriber
Reader
Life
}