Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Dec 11, 2024
1 parent 905e3f4 commit e542184
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
2 changes: 2 additions & 0 deletions pkg/chain/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (cbor *CborBlockStore) PutBlocks(ctx context.Context, blocks []*types.Block
func newChainStore(r repo.Repo, genTS *types.TipSet) *CborBlockStore {
tempBlock := r.Datastore()
cborStore := cbor.NewCborStore(tempBlock)
blkBytes, _ := genTS.Blocks()[0].ToStorageBlock()
_ = tempBlock.Put(context.Background(), blkBytes)
return &CborBlockStore{
Store: chain.NewStore(r.ChainDatastore(), tempBlock, genTS.At(0).Cid(), chainselector.Weight),
cborStore: cborStore,
Expand Down
62 changes: 29 additions & 33 deletions pkg/chainsync/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,45 +199,41 @@ func (syncer *Syncer) syncOne(ctx context.Context, parent, next *types.TipSet) e
stopwatch := syncOneTimer.Start()
defer stopwatch(ctx)

var err error

if !parent.Key().Equals(syncer.chainStore.GetCheckPoint().Key()) {
var wg errgroup.Group
for i := 0; i < next.Len(); i++ {
blk := next.At(i)
wg.Go(func() error {
// Fetch the URL.
err := syncer.blockValidator.ValidateFullBlock(ctx, blk)
if err == nil {
if err := syncer.chainStore.AddToTipSetTracker(ctx, blk); err != nil {
return fmt.Errorf("failed to add validated header to tipset tracker: %w", err)
}
var wg errgroup.Group
for i := 0; i < next.Len(); i++ {
blk := next.At(i)
wg.Go(func() error {
// Fetch the URL.
err := syncer.blockValidator.ValidateFullBlock(ctx, blk)
if err == nil {
if err := syncer.chainStore.AddToTipSetTracker(ctx, blk); err != nil {
return fmt.Errorf("failed to add validated header to tipset tracker: %w", err)
}
return err
})
}
err = wg.Wait()
if err != nil {
var rootNotMatch bool // nolint

if merr, isok := err.(*multierror.Error); isok {
for _, e := range merr.Errors {
if isRootNotMatch(e) {
rootNotMatch = true
break
}
}
} else {
rootNotMatch = isRootNotMatch(err) // nolint
}
return err
})
}
err := wg.Wait()
if err != nil {
var rootNotMatch bool // nolint

if rootNotMatch { // nolint
// todo: should here rollback, and re-compute?
_ = syncer.stmgr.Rollback(ctx, parent, next)
if merr, isok := err.(*multierror.Error); isok {
for _, e := range merr.Errors {
if isRootNotMatch(e) {
rootNotMatch = true
break
}
}
} else {
rootNotMatch = isRootNotMatch(err) // nolint
}

return fmt.Errorf("validate mining failed %w", err)
if rootNotMatch { // nolint
// todo: should here rollback, and re-compute?
_ = syncer.stmgr.Rollback(ctx, parent, next)
}

return fmt.Errorf("validate mining failed %w", err)
}

syncer.chainStore.PersistTipSetKey(ctx, next.Key())
Expand Down

0 comments on commit e542184

Please sign in to comment.