all: remove ethash pow, only retain shims needed for consensus and tests (#27178)
* all: remove ethash pow, only retain shims needed for consensus and tests * all: thank you linter * all: disallow launching Geth in legacy PoW mode * cmd/env/internal/t8ntool: remove dangling ethash flag
This commit is contained in:
+6
-25
@@ -70,9 +70,8 @@ type LightChain struct {
|
||||
wg sync.WaitGroup
|
||||
|
||||
// Atomic boolean switches:
|
||||
stopped atomic.Bool // whether LightChain is stopped or running
|
||||
procInterrupt atomic.Bool // interrupts chain insert
|
||||
disableCheckFreq atomic.Bool // disables header verification
|
||||
stopped atomic.Bool // whether LightChain is stopped or running
|
||||
procInterrupt atomic.Bool // interrupts chain insert
|
||||
}
|
||||
|
||||
// NewLightChain returns a fully initialised light chain using information
|
||||
@@ -345,7 +344,7 @@ func (lc *LightChain) Rollback(chain []common.Hash) {
|
||||
func (lc *LightChain) InsertHeader(header *types.Header) error {
|
||||
// Verify the header first before obtaining the lock
|
||||
headers := []*types.Header{header}
|
||||
if _, err := lc.hc.ValidateHeaderChain(headers, 100); err != nil {
|
||||
if _, err := lc.hc.ValidateHeaderChain(headers); err != nil {
|
||||
return err
|
||||
}
|
||||
// Make sure only one thread manipulates the chain at once
|
||||
@@ -381,23 +380,15 @@ func (lc *LightChain) SetCanonical(header *types.Header) error {
|
||||
// InsertHeaderChain attempts to insert the given header chain in to the local
|
||||
// chain, possibly creating a reorg. If an error is returned, it will return the
|
||||
// index number of the failing header as well an error describing what went wrong.
|
||||
//
|
||||
// The verify parameter can be used to fine tune whether nonce verification
|
||||
// should be done or not. The reason behind the optional check is because some
|
||||
// of the header retrieval mechanisms already need to verify nonces, as well as
|
||||
// because nonces can be verified sparsely, not needing to check each.
|
||||
//
|
||||
|
||||
// In the case of a light chain, InsertHeaderChain also creates and posts light
|
||||
// chain events when necessary.
|
||||
func (lc *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
|
||||
func (lc *LightChain) InsertHeaderChain(chain []*types.Header) (int, error) {
|
||||
if len(chain) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if lc.disableCheckFreq.Load() {
|
||||
checkFreq = 0
|
||||
}
|
||||
start := time.Now()
|
||||
if i, err := lc.hc.ValidateHeaderChain(chain, checkFreq); err != nil {
|
||||
if i, err := lc.hc.ValidateHeaderChain(chain); err != nil {
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -538,13 +529,3 @@ func (lc *LightChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscript
|
||||
func (lc *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
|
||||
return lc.scope.Track(new(event.Feed).Subscribe(ch))
|
||||
}
|
||||
|
||||
// DisableCheckFreq disables header validation. This is used for ultralight mode.
|
||||
func (lc *LightChain) DisableCheckFreq() {
|
||||
lc.disableCheckFreq.Store(true)
|
||||
}
|
||||
|
||||
// EnableCheckFreq enables header validation.
|
||||
func (lc *LightChain) EnableCheckFreq() {
|
||||
lc.disableCheckFreq.Store(false)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func newCanonical(n int) (ethdb.Database, *LightChain, error) {
|
||||
}
|
||||
// Header-only chain requested
|
||||
headers := makeHeaderChain(genesis.Header(), n, db, canonicalSeed)
|
||||
_, err := blockchain.InsertHeaderChain(headers, 1)
|
||||
_, err := blockchain.InsertHeaderChain(headers)
|
||||
return db, blockchain, err
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td
|
||||
}
|
||||
// Extend the newly created chain
|
||||
headerChainB := makeHeaderChain(LightChain2.CurrentHeader(), n, db, forkSeed)
|
||||
if _, err := LightChain2.InsertHeaderChain(headerChainB, 1); err != nil {
|
||||
if _, err := LightChain2.InsertHeaderChain(headerChainB); err != nil {
|
||||
t.Fatalf("failed to insert forking chain: %v", err)
|
||||
}
|
||||
// Sanity check that the forked chain can be imported into the original
|
||||
@@ -120,7 +120,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td
|
||||
func testHeaderChainImport(chain []*types.Header, lightchain *LightChain) error {
|
||||
for _, header := range chain {
|
||||
// Try and validate the header
|
||||
if err := lightchain.engine.VerifyHeader(lightchain.hc, header, true); err != nil {
|
||||
if err := lightchain.engine.VerifyHeader(lightchain.hc, header); err != nil {
|
||||
return err
|
||||
}
|
||||
// Manually insert the header into the database, but don't reorganize (allows subsequent testing)
|
||||
@@ -300,8 +300,8 @@ func testReorg(t *testing.T, first, second []int, td int64) {
|
||||
bc := newTestLightChain()
|
||||
|
||||
// Insert an easy and a difficult chain afterwards
|
||||
bc.InsertHeaderChain(makeHeaderChainWithDiff(bc.genesisBlock, first, 11), 1)
|
||||
bc.InsertHeaderChain(makeHeaderChainWithDiff(bc.genesisBlock, second, 22), 1)
|
||||
bc.InsertHeaderChain(makeHeaderChainWithDiff(bc.genesisBlock, first, 11))
|
||||
bc.InsertHeaderChain(makeHeaderChainWithDiff(bc.genesisBlock, second, 22))
|
||||
// Check that the chain is valid number and link wise
|
||||
prev := bc.CurrentHeader()
|
||||
for header := bc.GetHeaderByNumber(bc.CurrentHeader().Number.Uint64() - 1); header.Number.Uint64() != 0; prev, header = header, bc.GetHeaderByNumber(header.Number.Uint64()-1) {
|
||||
@@ -324,7 +324,7 @@ func TestBadHeaderHashes(t *testing.T) {
|
||||
var err error
|
||||
headers := makeHeaderChainWithDiff(bc.genesisBlock, []int{1, 2, 4}, 10)
|
||||
core.BadHashes[headers[2].Hash()] = true
|
||||
if _, err = bc.InsertHeaderChain(headers, 1); !errors.Is(err, core.ErrBannedHash) {
|
||||
if _, err = bc.InsertHeaderChain(headers); !errors.Is(err, core.ErrBannedHash) {
|
||||
t.Errorf("error mismatch: have: %v, want %v", err, core.ErrBannedHash)
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,7 @@ func TestReorgBadHeaderHashes(t *testing.T) {
|
||||
// Create a chain, import and ban afterwards
|
||||
headers := makeHeaderChainWithDiff(bc.genesisBlock, []int{1, 2, 3, 4}, 10)
|
||||
|
||||
if _, err := bc.InsertHeaderChain(headers, 1); err != nil {
|
||||
if _, err := bc.InsertHeaderChain(headers); err != nil {
|
||||
t.Fatalf("failed to import headers: %v", err)
|
||||
}
|
||||
if bc.CurrentHeader().Hash() != headers[3].Hash() {
|
||||
|
||||
+1
-1
@@ -292,7 +292,7 @@ func testChainOdr(t *testing.T, protocol int, fn odrTestFn) {
|
||||
for i, block := range gchain {
|
||||
headers[i] = block.Header()
|
||||
}
|
||||
if _, err := lightchain.InsertHeaderChain(headers, 1); err != nil {
|
||||
if _, err := lightchain.InsertHeaderChain(headers); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestTxPool(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := lightchain.InsertHeaderChain([]*types.Header{block.Header()}, 1); err != nil {
|
||||
if _, err := lightchain.InsertHeaderChain([]*types.Header{block.Header()}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user