From f2cc452d4cb1b2f5f2f5c89ced93c222a6a530a4 Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Tue, 13 Dec 2022 12:13:20 +0100 Subject: [PATCH] remove error from rcvBlock. type/docs gen --- build/params_2k.go | 4 ++-- chain/sub/bcast/consistent.go | 25 ++++++++++++++++--------- chain/sub/bcast/consistent_test.go | 10 ++++++---- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/build/params_2k.go b/build/params_2k.go index 48948ea50..390357bf2 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -134,5 +134,5 @@ const BootstrapPeerThreshold = 1 var WhitelistedBlock = cid.Undef // Reducing the delivery delay for equivocation of -// consistent broadcast to just one second. -const CBDeliveryDelay = 1 * time.Second +// consistent broadcast to just half a second. +const CBDeliveryDelay = 500 * time.Milisecond diff --git a/chain/sub/bcast/consistent.go b/chain/sub/bcast/consistent.go index 360476561..b69845476 100644 --- a/chain/sub/bcast/consistent.go +++ b/chain/sub/bcast/consistent.go @@ -7,12 +7,17 @@ import ( "sync" "time" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" + logging "github.com/ipfs/go-log/v2" "github.com/multiformats/go-multihash" + + "github.com/filecoin-project/go-state-types/abi" + + "github.com/filecoin-project/lotus/chain/types" ) +var log = logging.Logger("sub-cb") + const ( // GcSanityCheck determines the number of epochs that in the past // that will be garbage collected from the current epoch. @@ -86,14 +91,14 @@ func cidExists(cids []cid.Cid, c cid.Cid) bool { func (bInfo *blksInfo) eqErr() error { bInfo.cancel() - return fmt.Errorf("equivocation error detected. Different block with the same ticket already seen") + return fmt.Errorf("different blocks with the same ticket already seen") } func (cb *ConsistentBCast) Len() int { return len(cb.m) } -func (cb *ConsistentBCast) RcvBlock(ctx context.Context, blk *types.BlockMsg) error { +func (cb *ConsistentBCast) RcvBlock(ctx context.Context, blk *types.BlockMsg) { cb.lk.Lock() bcastDict, ok := cb.m[blk.Header.Height] if !ok { @@ -103,26 +108,28 @@ func (cb *ConsistentBCast) RcvBlock(ctx context.Context, blk *types.BlockMsg) er cb.lk.Unlock() key, err := BCastKey(blk.Header) if err != nil { - return err + log.Errorf("couldn't hash blk info for height %d: %s", blk.Header.Height, err) + return } blkCid := blk.Cid() bInfo, ok := bcastDict.load(key) if ok { if len(bInfo.blks) > 1 { - return bInfo.eqErr() + log.Errorf("equivocation detected for height %d: %s", blk.Header.Height, bInfo.eqErr()) + return } if !cidExists(bInfo.blks, blkCid) { bInfo.blks = append(bInfo.blks, blkCid) - return bInfo.eqErr() + log.Errorf("equivocation detected for height %d: %s", blk.Header.Height, bInfo.eqErr()) + return } - return nil + return } ctx, cancel := context.WithTimeout(ctx, cb.delay) bcastDict.store(key, &blksInfo{ctx, cancel, []cid.Cid{blkCid}}) - return nil } func (cb *ConsistentBCast) WaitForDelivery(bh *types.BlockHeader) error { diff --git a/chain/sub/bcast/consistent_test.go b/chain/sub/bcast/consistent_test.go index d06293876..ca84ab4b1 100644 --- a/chain/sub/bcast/consistent_test.go +++ b/chain/sub/bcast/consistent_test.go @@ -10,13 +10,15 @@ import ( "testing" "time" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/sub/bcast" - "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/require" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + "github.com/filecoin-project/lotus/chain/sub/bcast" + "github.com/filecoin-project/lotus/chain/types" ) const TEST_DELAY = 1 * time.Second