-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.go
67 lines (52 loc) · 2.18 KB
/
backend.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 core
import (
"github.com/0xDaoChain/go-ibft/messages"
"github.com/0xDaoChain/go-ibft/messages/proto"
)
// MessageConstructor defines a message constructor interface
type MessageConstructor interface {
// BuildPrePrepareMessage builds a PREPREPARE message based on the passed in proposal
BuildPrePrepareMessage(
proposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message
// BuildPrepareMessage builds a PREPARE message based on the passed in proposal
BuildPrepareMessage(proposalHash []byte, view *proto.View) *proto.Message
// BuildCommitMessage builds a COMMIT message based on the passed in proposal
BuildCommitMessage(proposalHash []byte, view *proto.View) *proto.Message
// BuildRoundChangeMessage builds a ROUND_CHANGE message based on the passed in proposal
BuildRoundChangeMessage(
proposal []byte,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message
}
// Verifier defines the verifier interface
type Verifier interface {
// IsValidBlock checks if the proposed block is child of parent
IsValidBlock(block []byte) bool
// IsValidSender checks if signature is from sender
IsValidSender(msg *proto.Message) bool
// IsProposer checks if the passed in ID is the Proposer for current view (sequence, round)
IsProposer(id []byte, height, round uint64) bool
// IsValidProposalHash checks if the hash matches the proposal
IsValidProposalHash(proposal, hash []byte) bool
// IsValidCommittedSeal checks if the seal for the proposal is valid
IsValidCommittedSeal(proposal []byte, committedSeal *messages.CommittedSeal) bool
}
// Backend defines an interface all backend implementations
// need to implement
type Backend interface {
MessageConstructor
Verifier
// BuildProposal builds a new block proposal
BuildProposal(view *proto.View) []byte
// InsertBlock inserts a proposal with the specified committed seals
InsertBlock(proposal []byte, committedSeals []*messages.CommittedSeal)
// ID returns the validator's ID
ID() []byte
// HasQuorum returns true if the quorum is reached
// for the specified block height.
HasQuorum(blockNumber uint64, messages []*proto.Message, msgType proto.MessageType) bool
}