diff --git a/pkg/server/server.go b/pkg/server/server.go index b1e4c0f5b..7730ee79b 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -56,7 +56,10 @@ func New(net protocol.Magic, port uint16) (*Server, error) { s.chain = chain // Setup sync manager - syncmgr := setupSyncManager(s) + syncmgr, err := setupSyncManager(s) + if err != nil { + return nil, err + } s.smg = syncmgr // Setup connection manager diff --git a/pkg/server/syncmgr.go b/pkg/server/syncmgr.go index 7de87188b..e6020d5b9 100644 --- a/pkg/server/syncmgr.go +++ b/pkg/server/syncmgr.go @@ -11,7 +11,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/wire/util" ) -func setupSyncManager(s *Server) *syncmgr.Syncmgr { +func setupSyncManager(s *Server) (*syncmgr.Syncmgr, error) { cfg := &syncmgr.Config{ ProcessBlock: s.processBlock, @@ -27,7 +27,15 @@ func setupSyncManager(s *Server) *syncmgr.Syncmgr { FetchBlockAgain: s.fetchBlockAgain, } - return syncmgr.New(cfg) + // Add nextBlockIndex in syncmgr + lastBlock, err := s.chain.Db.GetLastBlock() + if err != nil { + return nil, err + } + + nextBlockIndex := lastBlock.Index + 1 + + return syncmgr.New(cfg, nextBlockIndex), nil } func (s *Server) onHeader(peer *peer.Peer, hdrsMessage *payload.HeadersMessage) {