Skip to content

Commit 0ca8941

Browse files
committed
core, eth, internal/ethapi: get rid of unused ChainSideEvent
1 parent 1a02799 commit 0ca8941

File tree

8 files changed

+0
-101
lines changed

8 files changed

+0
-101
lines changed

core/blockchain.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,9 +2326,6 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
23262326
// Deleted logs + blocks:
23272327
var deletedLogs []*types.Log
23282328
for i := len(oldChain) - 1; i >= 0; i-- {
2329-
// Also send event for blocks removed from the canon chain.
2330-
bc.chainSideFeed.Send(ChainSideEvent{Header: oldChain[i].Header()})
2331-
23322329
// Collect deleted logs for notification
23332330
if logs := bc.collectLogs(oldChain[i], true); len(logs) > 0 {
23342331
deletedLogs = append(deletedLogs, logs...)

core/blockchain_reader.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Su
430430
return bc.scope.Track(bc.chainHeadFeed.Subscribe(ch))
431431
}
432432

433-
// SubscribeChainSideEvent registers a subscription of ChainSideEvent.
434-
func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription {
435-
return bc.scope.Track(bc.chainSideFeed.Subscribe(ch))
436-
}
437-
438433
// SubscribeLogsEvent registers a subscription of []*types.Log.
439434
func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
440435
return bc.scope.Track(bc.logsFeed.Subscribe(ch))

core/blockchain_test.go

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,84 +1332,6 @@ func checkLogEvents(t *testing.T, logsCh <-chan []*types.Log, rmLogsCh <-chan Re
13321332
}
13331333
}
13341334

1335-
func TestReorgSideEvent(t *testing.T) {
1336-
testReorgSideEvent(t, rawdb.HashScheme)
1337-
testReorgSideEvent(t, rawdb.PathScheme)
1338-
}
1339-
1340-
func testReorgSideEvent(t *testing.T, scheme string) {
1341-
var (
1342-
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
1343-
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
1344-
gspec = &Genesis{
1345-
Config: params.TestChainConfig,
1346-
Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}},
1347-
}
1348-
signer = types.LatestSigner(gspec.Config)
1349-
)
1350-
blockchain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil)
1351-
defer blockchain.Stop()
1352-
1353-
_, chain, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 3, func(i int, gen *BlockGen) {})
1354-
if _, err := blockchain.InsertChain(chain); err != nil {
1355-
t.Fatalf("failed to insert chain: %v", err)
1356-
}
1357-
1358-
_, replacementBlocks, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 4, func(i int, gen *BlockGen) {
1359-
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, gen.header.BaseFee, nil), signer, key1)
1360-
if i == 2 {
1361-
gen.OffsetTime(-9)
1362-
}
1363-
if err != nil {
1364-
t.Fatalf("failed to create tx: %v", err)
1365-
}
1366-
gen.AddTx(tx)
1367-
})
1368-
chainSideCh := make(chan ChainSideEvent, 64)
1369-
blockchain.SubscribeChainSideEvent(chainSideCh)
1370-
if _, err := blockchain.InsertChain(replacementBlocks); err != nil {
1371-
t.Fatalf("failed to insert chain: %v", err)
1372-
}
1373-
1374-
expectedSideHashes := map[common.Hash]bool{
1375-
chain[0].Hash(): true,
1376-
chain[1].Hash(): true,
1377-
chain[2].Hash(): true,
1378-
}
1379-
1380-
i := 0
1381-
1382-
const timeoutDura = 10 * time.Second
1383-
timeout := time.NewTimer(timeoutDura)
1384-
done:
1385-
for {
1386-
select {
1387-
case ev := <-chainSideCh:
1388-
if _, ok := expectedSideHashes[ev.Header.Hash()]; !ok {
1389-
t.Errorf("%d: didn't expect %x to be in side chain", i, ev.Header.Hash())
1390-
}
1391-
i++
1392-
1393-
if i == len(expectedSideHashes) {
1394-
timeout.Stop()
1395-
1396-
break done
1397-
}
1398-
timeout.Reset(timeoutDura)
1399-
1400-
case <-timeout.C:
1401-
t.Fatalf("Timeout. Possibly not all blocks were triggered for sideevent: %v", i)
1402-
}
1403-
}
1404-
1405-
// make sure no more events are fired
1406-
select {
1407-
case e := <-chainSideCh:
1408-
t.Errorf("unexpected event fired: %v", e)
1409-
case <-time.After(250 * time.Millisecond):
1410-
}
1411-
}
1412-
14131335
// Tests if the canonical block can be fetched from the database during chain insertion.
14141336
func TestCanonicalBlockRetrieval(t *testing.T) {
14151337
testCanonicalBlockRetrieval(t, rawdb.HashScheme)

core/events.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ type ChainEvent struct {
3333
Header *types.Header
3434
}
3535

36-
type ChainSideEvent struct {
37-
Header *types.Header
38-
}
39-
4036
type ChainHeadEvent struct {
4137
Header *types.Header
4238
}

eth/api_backend.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ func (b *EthAPIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) e
275275
return b.eth.BlockChain().SubscribeChainHeadEvent(ch)
276276
}
277277

278-
func (b *EthAPIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription {
279-
return b.eth.BlockChain().SubscribeChainSideEvent(ch)
280-
}
281-
282278
func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
283279
return b.eth.BlockChain().SubscribeLogsEvent(ch)
284280
}

internal/ethapi/api_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,6 @@ func (b testBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscr
587587
func (b testBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription {
588588
panic("implement me")
589589
}
590-
func (b testBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription {
591-
panic("implement me")
592-
}
593590
func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
594591
panic("implement me")
595592
}

internal/ethapi/backend.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ type Backend interface {
7171
GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
7272
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
7373
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
74-
SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
7574

7675
// Transaction pool API
7776
SendTx(ctx context.Context, signedTx *types.Transaction) error

internal/ethapi/transaction_args_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ func (b *backendMock) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subsc
377377
func (b *backendMock) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription {
378378
return nil
379379
}
380-
func (b *backendMock) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription {
381-
return nil
382-
}
383380
func (b *backendMock) SendTx(ctx context.Context, signedTx *types.Transaction) error { return nil }
384381
func (b *backendMock) GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error) {
385382
return false, nil, [32]byte{}, 0, 0, nil

0 commit comments

Comments
 (0)