From a6135b62cee76cf07090b971ce0891309a87c9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 11 Nov 2019 23:37:34 +0100 Subject: [PATCH 1/5] sync: Mark chains with bad blocks as bad too --- build/params.go | 4 ++-- chain/sync.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/build/params.go b/build/params.go index 0c4908b74..f54491068 100644 --- a/build/params.go +++ b/build/params.go @@ -122,8 +122,8 @@ func init() { } // Sync -const BadBlockCacheSize = 8192 +const BadBlockCacheSize = 1 << 15 // assuming 4000 blocks per round, this lets us not lose any messages across a -// 10 block reorg. +// 10 block reorg. const BlsSignatureCacheSize = 40000 diff --git a/chain/sync.go b/chain/sync.go index 8e62eefa3..19a48e59f 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -755,10 +755,16 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to syncer.syncState.SetHeight(blockSet[len(blockSet)-1].Height()) + var acceptedBlocks []cid.Cid + loop: for blockSet[len(blockSet)-1].Height() > untilHeight { for _, bc := range at { if syncer.bad.Has(bc) { + for _, b := range acceptedBlocks { + syncer.bad.Add(b) + } + return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc) } } @@ -766,6 +772,8 @@ loop: // If, for some reason, we have a suffix of the chain locally, handle that here ts, err := syncer.store.LoadTipSet(at) if err == nil { + acceptedBlocks = append(acceptedBlocks, at...) + blockSet = append(blockSet, ts) at = ts.Parents() continue @@ -801,12 +809,18 @@ loop: } for _, bc := range b.Cids() { if syncer.bad.Has(bc) { + for _, b := range acceptedBlocks { + syncer.bad.Add(b) + } + return nil, xerrors.Errorf("chain contained block marked previously as bad (%s, %s)", from.Cids(), bc) } } blockSet = append(blockSet, b) } + acceptedBlocks = append(acceptedBlocks, at...) + syncer.syncState.SetHeight(blks[len(blks)-1].Height()) at = blks[len(blks)-1].Parents() } From 92b9f67327dc300e9986f6c4f2fce0b7de334d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 12 Nov 2019 11:05:18 +0100 Subject: [PATCH 2/5] Reduce log spam more --- cmd/lotus/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index 38fc478ac..b9ed5fb1b 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -16,7 +16,8 @@ import ( func main() { logging.SetLogLevel("*", "INFO") logging.SetLogLevel("dht", "ERROR") - logging.SetLogLevel("swarm", "WARN") + logging.SetLogLevel("swarm2", "WARN") + logging.SetLogLevel("bitswap", "WARN") local := []*cli.Command{ DaemonCmd, From 2d8ad4a1de7a082f8819cf9f48541b3d73784193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 12 Nov 2019 11:18:46 +0100 Subject: [PATCH 3/5] sync: batching PersistHeaders --- chain/gen/gen.go | 2 +- chain/store/store.go | 18 +++++++++++------- chain/sync.go | 11 ++++++----- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 0d951f1fe..93483f525 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -269,7 +269,7 @@ func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Ad return nil, xerrors.Errorf("making a block for next tipset failed: %w", err) } - if err := cg.cs.PersistBlockHeader(fblk.Header); err != nil { + if err := cg.cs.PersistBlockHeaders(fblk.Header); err != nil { return nil, xerrors.Errorf("chainstore AddBlock: %w", err) } diff --git a/chain/store/store.go b/chain/store/store.go index dcef64027..f78e24beb 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -198,7 +198,7 @@ func (cs *ChainStore) SetGenesis(b *types.BlockHeader) error { func (cs *ChainStore) PutTipSet(ctx context.Context, ts *types.TipSet) error { for _, b := range ts.Blocks() { - if err := cs.PersistBlockHeader(b); err != nil { + if err := cs.PersistBlockHeaders(b); err != nil { return err } } @@ -423,13 +423,17 @@ func (cs *ChainStore) AddToTipSetTracker(b *types.BlockHeader) error { return nil } -func (cs *ChainStore) PersistBlockHeader(b *types.BlockHeader) error { - sb, err := b.ToStorageBlock() - if err != nil { - return err +func (cs *ChainStore) PersistBlockHeaders(b ...*types.BlockHeader) (err error) { + sbs := make([]block.Block, len(b)) + + for i, header := range b { + sbs[i], err = header.ToStorageBlock() + if err != nil { + return err + } } - return cs.bs.Put(sb) + return cs.bs.PutMany(sbs) } type storable interface { @@ -487,7 +491,7 @@ func (cs *ChainStore) expandTipset(b *types.BlockHeader) (*types.TipSet, error) } func (cs *ChainStore) AddBlock(ctx context.Context, b *types.BlockHeader) error { - if err := cs.PersistBlockHeader(b); err != nil { + if err := cs.PersistBlockHeaders(b); err != nil { return err } diff --git a/chain/sync.go b/chain/sync.go index 19a48e59f..929b967e1 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -1004,13 +1004,14 @@ func (syncer *Syncer) collectChain(ctx context.Context, ts *types.TipSet) error syncer.syncState.SetStage(api.StagePersistHeaders) + toPersist := make([]*types.BlockHeader, 0, len(headers)*build.BlocksPerEpoch) for _, ts := range headers { - for _, b := range ts.Blocks() { - if err := syncer.store.PersistBlockHeader(b); err != nil { - return xerrors.Errorf("failed to persist synced blocks to the chainstore: %w", err) - } - } + toPersist = append(toPersist, ts.Blocks()...) } + if err := syncer.store.PersistBlockHeaders(toPersist...); err != nil { + return xerrors.Errorf("failed to persist synced blocks to the chainstore: %w", err) + } + toPersist = nil syncer.syncState.SetStage(api.StageMessages) From 3a1c73a2b17e287bd11e80029248f29b3ecc747c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 12 Nov 2019 12:42:19 +0100 Subject: [PATCH 4/5] mpool: Fix RecoverSig type cast --- chain/messagepool.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/messagepool.go b/chain/messagepool.go index 63aa1bedb..7fa476b8c 100644 --- a/chain/messagepool.go +++ b/chain/messagepool.go @@ -322,7 +322,7 @@ func (mp *MessagePool) RecoverSig(msg *types.Message) *types.SignedMessage { if !ok { return nil } - sig, ok := val.(*types.Signature) + sig, ok := val.(types.Signature) if !ok { log.Warnf("value in signature cache was not a signature (got %T)", val) return nil @@ -330,6 +330,6 @@ func (mp *MessagePool) RecoverSig(msg *types.Message) *types.SignedMessage { return &types.SignedMessage{ Message: *msg, - Signature: *sig, + Signature: sig, } } From a9861e116b92058a3f439f1f90aca222a2ec07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 12 Nov 2019 12:45:25 +0100 Subject: [PATCH 5/5] bolcksync: set message in 203 response --- chain/blocksync/blocksync.go | 1 + 1 file changed, 1 insertion(+) diff --git a/chain/blocksync/blocksync.go b/chain/blocksync/blocksync.go index fd352a9ea..81bd1920d 100644 --- a/chain/blocksync/blocksync.go +++ b/chain/blocksync/blocksync.go @@ -129,6 +129,7 @@ func (bss *BlockSyncService) processRequest(ctx context.Context, req *BlockSyncR log.Warn("encountered error while responding to block sync request: ", err) return &BlockSyncResponse{ Status: 203, + Message: err.Error(), }, nil }