Skip to content

Commit b1f0efa

Browse files
jsvisakielbarry
authored andcommitted
core: remove dead code, limit test code scope (ethereum#17006)
* core: move test util var/func to test file * core: remove useless func
1 parent 7c905a1 commit b1f0efa

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

core/blockchain_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/ethereum/go-ethereum/common"
28+
"github.com/ethereum/go-ethereum/consensus"
2829
"github.com/ethereum/go-ethereum/consensus/ethash"
2930
"github.com/ethereum/go-ethereum/core/rawdb"
3031
"github.com/ethereum/go-ethereum/core/state"
@@ -35,6 +36,39 @@ import (
3536
"github.com/ethereum/go-ethereum/params"
3637
)
3738

39+
// So we can deterministically seed different blockchains
40+
var (
41+
canonicalSeed = 1
42+
forkSeed = 2
43+
)
44+
45+
// newCanonical creates a chain database, and injects a deterministic canonical
46+
// chain. Depending on the full flag, if creates either a full block chain or a
47+
// header only chain.
48+
func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *BlockChain, error) {
49+
var (
50+
db = ethdb.NewMemDatabase()
51+
genesis = new(Genesis).MustCommit(db)
52+
)
53+
54+
// Initialize a fresh chain with only a genesis block
55+
blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
56+
// Create and inject the requested chain
57+
if n == 0 {
58+
return db, blockchain, nil
59+
}
60+
if full {
61+
// Full block-chain requested
62+
blocks := makeBlockChain(genesis, n, engine, db, canonicalSeed)
63+
_, err := blockchain.InsertChain(blocks)
64+
return db, blockchain, err
65+
}
66+
// Header-only chain requested
67+
headers := makeHeaderChain(genesis.Header(), n, engine, db, canonicalSeed)
68+
_, err := blockchain.InsertHeaderChain(headers, 1)
69+
return db, blockchain, err
70+
}
71+
3872
// Test fork of length N starting from block i
3973
func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, comparator func(td1, td2 *big.Int)) {
4074
// Copy old chain up to #i into a new db

core/chain_makers.go

-33
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ import (
3030
"github.com/ethereum/go-ethereum/params"
3131
)
3232

33-
// So we can deterministically seed different blockchains
34-
var (
35-
canonicalSeed = 1
36-
forkSeed = 2
37-
)
38-
3933
// BlockGen creates blocks for testing.
4034
// See GenerateChain for a detailed explanation.
4135
type BlockGen struct {
@@ -252,33 +246,6 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
252246
}
253247
}
254248

255-
// newCanonical creates a chain database, and injects a deterministic canonical
256-
// chain. Depending on the full flag, if creates either a full block chain or a
257-
// header only chain.
258-
func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *BlockChain, error) {
259-
var (
260-
db = ethdb.NewMemDatabase()
261-
genesis = new(Genesis).MustCommit(db)
262-
)
263-
264-
// Initialize a fresh chain with only a genesis block
265-
blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
266-
// Create and inject the requested chain
267-
if n == 0 {
268-
return db, blockchain, nil
269-
}
270-
if full {
271-
// Full block-chain requested
272-
blocks := makeBlockChain(genesis, n, engine, db, canonicalSeed)
273-
_, err := blockchain.InsertChain(blocks)
274-
return db, blockchain, err
275-
}
276-
// Header-only chain requested
277-
headers := makeHeaderChain(genesis.Header(), n, engine, db, canonicalSeed)
278-
_, err := blockchain.InsertHeaderChain(headers, 1)
279-
return db, blockchain, err
280-
}
281-
282249
// makeHeaderChain creates a deterministic chain of headers rooted at parent.
283250
func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header {
284251
blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)

core/types/transaction.go

-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ var (
3535
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
3636
)
3737

38-
// deriveSigner makes a *best* guess about which signer to use.
39-
func deriveSigner(V *big.Int) Signer {
40-
if V.Sign() != 0 && isProtectedV(V) {
41-
return NewEIP155Signer(deriveChainId(V))
42-
} else {
43-
return HomesteadSigner{}
44-
}
45-
}
46-
4738
type Transaction struct {
4839
data txdata
4940
// caches

core/vm/memory_table.go

-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ func memoryCall(stack *Stack) *big.Int {
6565
return math.BigMax(x, y)
6666
}
6767

68-
func memoryCallCode(stack *Stack) *big.Int {
69-
x := calcMemSize(stack.Back(5), stack.Back(6))
70-
y := calcMemSize(stack.Back(3), stack.Back(4))
71-
72-
return math.BigMax(x, y)
73-
}
7468
func memoryDelegateCall(stack *Stack) *big.Int {
7569
x := calcMemSize(stack.Back(4), stack.Back(5))
7670
y := calcMemSize(stack.Back(2), stack.Back(3))

0 commit comments

Comments
 (0)