quick mechanism to prevent miners from submitting slashable blocks
This commit is contained in:
parent
ee4f503e10
commit
c6186a03f1
@ -2,6 +2,7 @@ package miner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/gen"
|
"github.com/filecoin-project/lotus/chain/gen"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
lru "github.com/hashicorp/golang-lru"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
@ -22,6 +24,7 @@ var log = logging.Logger("miner")
|
|||||||
type waitFunc func(ctx context.Context, baseTime uint64) error
|
type waitFunc func(ctx context.Context, baseTime uint64) error
|
||||||
|
|
||||||
func NewMiner(api api.FullNode, epp gen.ElectionPoStProver) *Miner {
|
func NewMiner(api api.FullNode, epp gen.ElectionPoStProver) *Miner {
|
||||||
|
arc, _ := lru.NewARC(10000)
|
||||||
return &Miner{
|
return &Miner{
|
||||||
api: api,
|
api: api,
|
||||||
epp: epp,
|
epp: epp,
|
||||||
@ -32,6 +35,7 @@ func NewMiner(api api.FullNode, epp gen.ElectionPoStProver) *Miner {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
minedBlockHeights: arc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +52,8 @@ type Miner struct {
|
|||||||
waitFunc waitFunc
|
waitFunc waitFunc
|
||||||
|
|
||||||
lastWork *MiningBase
|
lastWork *MiningBase
|
||||||
|
|
||||||
|
minedBlockHeights *lru.ARCCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Miner) Addresses() ([]address.Address, error) {
|
func (m *Miner) Addresses() ([]address.Address, error) {
|
||||||
@ -200,6 +206,17 @@ eventLoop:
|
|||||||
mWon[b.Header.Miner] = struct{}{}
|
mWon[b.Header.Miner] = struct{}{}
|
||||||
}
|
}
|
||||||
for _, b := range blks {
|
for _, b := range blks {
|
||||||
|
// TODO: this code was written to handle creating blocks for multiple miners.
|
||||||
|
// However, we don't use that, and we probably never will. So even though this code will
|
||||||
|
// never see different miners, i'm going to handle the caching as if it was going to.
|
||||||
|
// We can clean it up later when we remove all the multiple miner logic.
|
||||||
|
blkKey := fmt.Sprintf("%s-%d", b.Header.Miner, b.Header.Height)
|
||||||
|
if _, ok := m.minedBlockHeights.Get(blkKey); ok {
|
||||||
|
log.Warnw("Created a block at the same height as another block we've created", "height", b.Header.Height, "miner", b.Header.Miner, "parents", b.Header.Parents)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m.minedBlockHeights.Add(blkKey, true)
|
||||||
if err := m.api.SyncSubmitBlock(ctx, b); err != nil {
|
if err := m.api.SyncSubmitBlock(ctx, b); err != nil {
|
||||||
log.Errorf("failed to submit newly mined block: %s", err)
|
log.Errorf("failed to submit newly mined block: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user