-
Notifications
You must be signed in to change notification settings - Fork 461
/
chainsync.go
73 lines (63 loc) · 2.1 KB
/
chainsync.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
package chainsync
import (
"context"
chain2 "github.com/filecoin-project/venus/app/submodule/chain"
"github.com/filecoin-project/venus/pkg/chainsync/types"
"github.com/filecoin-project/venus/pkg/consensus"
"github.com/filecoin-project/venus/pkg/net/exchange"
"github.com/filecoin-project/venus/pkg/statemanger"
blockstoreutil "github.com/filecoin-project/venus/venus-shared/blockstore"
types2 "github.com/filecoin-project/venus/venus-shared/types"
"github.com/filecoin-project/venus/pkg/chainsync/dispatcher"
"github.com/filecoin-project/venus/pkg/chainsync/syncer"
"github.com/filecoin-project/venus/pkg/clock"
"github.com/filecoin-project/venus/pkg/fork"
)
// BlockProposer allows callers to propose new blocks for inclusion in the chain.
type BlockProposer interface {
SetConcurrent(number int64)
Concurrent() int64
SyncTracker() *types.TargetTracker
SendHello(ci *types2.ChainInfo) error
SendOwnBlock(ci *types2.ChainInfo) error
SendGossipBlock(ci *types2.ChainInfo) error
IncomingBlocks(ctx context.Context) (<-chan *types2.BlockHeader, error)
}
var _ = (BlockProposer)((*dispatcher.Dispatcher)(nil))
// Manager sync the chain.
type Manager struct {
dispatcher *dispatcher.Dispatcher
}
// NewManager creates a new chain sync manager.
func NewManager(
stmgr *statemanger.Stmgr,
hv *consensus.BlockValidator,
submodule *chain2.ChainSubmodule,
cs syncer.ChainSelector,
bsstore blockstoreutil.Blockstore,
exchangeClient exchange.Client,
c clock.Clock,
fork fork.IFork,
) (Manager, error) {
chainSyncer, err := syncer.NewSyncer(stmgr, hv, cs, submodule.ChainReader,
submodule.MessageStore, bsstore,
exchangeClient, c, fork)
if err != nil {
return Manager{}, err
}
return Manager{
dispatcher: dispatcher.NewDispatcher(struct {
*syncer.Syncer
*consensus.BlockValidator
}{Syncer: chainSyncer, BlockValidator: hv}, submodule.ChainReader),
}, nil
}
// Start starts the chain sync manager.
func (m *Manager) Start(ctx context.Context) error {
m.dispatcher.Start(ctx)
return nil
}
// BlockProposer returns the block proposer.
func (m *Manager) BlockProposer() BlockProposer {
return m.dispatcher
}