-package netsync
+package chainmgr
import (
"container/list"
- "encoding/hex"
"encoding/json"
"testing"
"time"
"github.com/vapor/consensus"
"github.com/vapor/errors"
+ msgs "github.com/vapor/netsync/messages"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
"github.com/vapor/test/mock"
go A2B.postMan()
}
- a.blockKeeper.syncPeer = a.peers.getPeer("test node B")
+ a.blockKeeper.syncPeer = a.peers.GetPeer("test node B")
if err := a.blockKeeper.fastBlockSync(c.checkPoint); errors.Root(err) != c.err {
t.Errorf("case %d: got %v want %v", i, err, c.err)
}
},
{
checkPoints: []consensus.Checkpoint{
- {10000, bc.Hash{V0: 1}},
+ {Height: 10000, Hash: bc.Hash{V0: 1}},
},
bestHeight: 5000,
- want: &consensus.Checkpoint{10000, bc.Hash{V0: 1}},
+ want: &consensus.Checkpoint{Height: 10000, Hash: bc.Hash{V0: 1}},
},
{
checkPoints: []consensus.Checkpoint{
- {10000, bc.Hash{V0: 1}},
- {20000, bc.Hash{V0: 2}},
- {30000, bc.Hash{V0: 3}},
+ {Height: 10000, Hash: bc.Hash{V0: 1}},
+ {Height: 20000, Hash: bc.Hash{V0: 2}},
+ {Height: 30000, Hash: bc.Hash{V0: 3}},
},
bestHeight: 15000,
- want: &consensus.Checkpoint{20000, bc.Hash{V0: 2}},
+ want: &consensus.Checkpoint{Height: 20000, Hash: bc.Hash{V0: 2}},
},
{
checkPoints: []consensus.Checkpoint{
- {10000, bc.Hash{V0: 1}},
- {20000, bc.Hash{V0: 2}},
- {30000, bc.Hash{V0: 3}},
+ {Height: 10000, Hash: bc.Hash{V0: 1}},
+ {Height: 20000, Hash: bc.Hash{V0: 2}},
+ {Height: 30000, Hash: bc.Hash{V0: 3}},
},
bestHeight: 10000,
- want: &consensus.Checkpoint{20000, bc.Hash{V0: 2}},
+ want: &consensus.Checkpoint{Height: 20000, Hash: bc.Hash{V0: 2}},
},
{
checkPoints: []consensus.Checkpoint{
- {10000, bc.Hash{V0: 1}},
- {20000, bc.Hash{V0: 2}},
- {30000, bc.Hash{V0: 3}},
+ {Height: 10000, Hash: bc.Hash{V0: 1}},
+ {Height: 20000, Hash: bc.Hash{V0: 2}},
+ {Height: 30000, Hash: bc.Hash{V0: 3}},
},
bestHeight: 35000,
want: nil,
go A2B.postMan()
}
- a.blockKeeper.syncPeer = a.peers.getPeer("test node B")
+ a.blockKeeper.syncPeer = a.peers.GetPeer("test node B")
if err := a.blockKeeper.regularBlockSync(c.syncHeight); errors.Root(err) != c.err {
t.Errorf("case %d: got %v want %v", i, err, c.err)
}
go A2B.postMan()
}
- a.blockKeeper.syncPeer = a.peers.getPeer("test node B")
- b.blockKeeper.syncPeer = b.peers.getPeer("test node A")
+ a.blockKeeper.syncPeer = a.peers.GetPeer("test node B")
+ b.blockKeeper.syncPeer = b.peers.GetPeer("test node A")
cases := []struct {
syncTimeout time.Duration
- testNode *SyncManager
+ testNode *ChainManager
requireHeight uint64
want *types.Block
err error
completed := make(chan error)
go func() {
msgBytes := <-F2S.msgCh
- _, msg, _ := DecodeMessage(msgBytes)
+ _, msg, _ := decodeMessage(msgBytes)
switch m := msg.(type) {
- case *MerkleBlockMessage:
+ case *msgs.MerkleBlockMessage:
var relatedTxIDs []*bc.Hash
for _, rawTx := range m.RawTxDatas {
tx := &types.Tx{}
}
}()
- spvPeer := fullNode.peers.getPeer("spv_node")
+ spvPeer := fullNode.peers.GetPeer("spv_node")
for i := 0; i < len(c.relatedTxIndex); i++ {
- spvPeer.filterAdds.Add(hex.EncodeToString(txs[c.relatedTxIndex[i]].Outputs[0].ControlProgram()))
+ spvPeer.AddFilterAddress(txs[c.relatedTxIndex[i]].Outputs[0].ControlProgram())
}
- msg := &GetMerkleBlockMessage{RawHash: targetBlock.Hash().Byte32()}
+ msg := &msgs.GetMerkleBlockMessage{RawHash: targetBlock.Hash().Byte32()}
fullNode.handleGetMerkleBlockMsg(spvPeer, msg)
if err := <-completed; err != nil {
t.Fatal(err)