sync: have tree diffs queried and applied, then go back to finding new view IDs to sync to
@@ -43,6 +43,7 @@ func (s *syncer) work() {
var rootID common.TransactionID
var root *wavelet.Transaction
+ for {
for {
err := s.queryForLatestView()
@@ -54,6 +55,7 @@ func (s *syncer) work() {
// The view ID we came to consensus to being the latest within the network
// is less than or equal to ours. Go back to square one.
rootID = s.resolver.Preferred().(common.TransactionID)
+
s.resolver.Reset()
if root = s.getRootByID(rootID); s.ledger.Root().ID == rootID || root.ViewID+1 <= s.ledger.ViewID() {
@@ -67,11 +69,27 @@ func (s *syncer) work() {
time.Sleep(1 * time.Millisecond)
}
+ var peerIDs []protocol.ID
+
+ for peerID := range s.accounts[rootID] {
+ peerIDs = append(peerIDs, peerID)
+ }
+
// Reset all state used for coming to consensus about the latest view-graph root.
s.roots = make(map[common.TransactionID]*wavelet.Transaction)
+ s.accounts = make(map[common.TransactionID]map[protocol.ID]struct{})
+
+ // TODO(kenta): stop any broadcasting/querying
- // TODO(kenta): stop any broadcasting/querying and download account state tree diffs
fmt.Println(root)
+
+ err := s.queryAndApplyDiff(peerIDs, root)
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ // TODO(kenta): have the ledger start serving broadcasts/queries again
+ }
}
func (s *syncer) addRootIfNotExists(account protocol.ID, root *wavelet.Transaction) {
@@ -179,7 +197,9 @@ func (s *syncer) queryAndApplyDiff(peerIDs []protocol.ID, root *wavelet.Transact
continue
}
- s.ledger.Reset(root, snapshot)
+ if _, err := s.ledger.Reset(root, snapshot); err != nil {
+ return err
+ }
}
return ErrNoDiffFound
