From b71f771acbfcdbaa273a15e126051b79a51fc542 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 22 Jun 2020 16:09:05 -0700 Subject: [PATCH 1/2] run block validation for tipsets in parallel --- chain/sync.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 26f30d95b..19ddac108 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -466,16 +466,25 @@ func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet) return nil } + var futures []async.ErrorFuture for _, b := range fts.Blocks { - if err := syncer.ValidateBlock(ctx, b); err != nil { - if isPermanent(err) { - syncer.bad.Add(b.Cid(), err.Error()) + futures = append(futures, async.Err(func() error { + if err := syncer.ValidateBlock(ctx, b); err != nil { + if isPermanent(err) { + syncer.bad.Add(b.Cid(), err.Error()) + } + return xerrors.Errorf("validating block %s: %w", b.Cid(), err) } - return xerrors.Errorf("validating block %s: %w", b.Cid(), err) - } - if err := syncer.sm.ChainStore().AddToTipSetTracker(b.Header); err != nil { - return xerrors.Errorf("failed to add validated header to tipset tracker: %w", err) + if err := syncer.sm.ChainStore().AddToTipSetTracker(b.Header); err != nil { + return xerrors.Errorf("failed to add validated header to tipset tracker: %w", err) + } + return nil + })) + } + for _, f := range futures { + if err := f.AwaitContext(ctx); err != nil { + return err } } return nil From 9e70e9524231ae98375a2ac93b3be4bd22e78992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 23 Jun 2020 13:21:01 +0200 Subject: [PATCH 2/2] sync: Correctly pass blocks to ValidateBlock --- chain/sync.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chain/sync.go b/chain/sync.go index 19ddac108..f20637c9e 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -468,6 +468,8 @@ func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet) var futures []async.ErrorFuture for _, b := range fts.Blocks { + b := b // rebind to a scoped variable + futures = append(futures, async.Err(func() error { if err := syncer.ValidateBlock(ctx, b); err != nil { if isPermanent(err) {