Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop server elegantly instead of panic when db closed #191

Merged
merged 13 commits into from
Sep 22, 2022

Conversation

DarianShawn
Copy link
Collaborator

Description

The close sequence was not appropriate. It closed the db first, which might be processing block written job. Then close network, etc.

This PR

  • Close consensus, network and txpool first, then stop blockchain executor processing block before close the db.
  • Removes the panic logic when closed.
  • Adds some nil check if we get empty code of a contract address.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

Manual tests

  • Set up a MainNet node and join the network.
  • Stop the server when syncing block. Repeat it several times.

In target branch, we'll get some logs below, which would never happen in the PR branch:

[SIGNAL] Caught signal: interrupt
Gracefully shutting down client...

panic: leveldb: closed

goroutine 157 [running]:
github.com/dogechain-lab/dogechain/state/immutable-trie.(*KVStorage).Get(0x0, {0xc042fb5600, 0xc047fda710, 0xc040e80580})
	/go/src/state/immutable-trie/storage.go:77 +0x96
github.com/dogechain-lab/dogechain/state/immutable-trie.GetNode({0xc042fb5600, 0x41473e5, 0xc047fda7c8}, {0x58acee8, 0xc000588380})
	/go/src/state/immutable-trie/storage.go:155 +0x88
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).lookup(0xc047fdaa60, {0x50a3680, 0xc040e80500}, {0xc0387666e3, 0xc0077bfec0, 0xc000588380})
	/go/src/state/immutable-trie/trie.go:274 +0x1c8
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).lookup(0xc047fdaa60, {0x512dfa0, 0xc0408c88c0}, {0xc0387666e2, 0xc000588380, 0x8})
	/go/src/state/immutable-trie/trie.go:313 +0x2ea
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).lookup(0xc047fdaa60, {0x50a3680, 0xc03d68f560}, {0xc0387666e2, 0x400dd94, 0x0})
	/go/src/state/immutable-trie/trie.go:283 +0x212
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).lookup(0xc047fdaa60, {0x512dfa0, 0xc0500a37c0}, {0xc0387666e1, 0x404ef32, 0x41})
	/go/src/state/immutable-trie/trie.go:313 +0x2ea
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).lookup(0xc047fdaa60, {0x512dfa0, 0xc03d212640}, {0xc0387666e0, 0x10100c047fdaa50, 0x32399218})
	/go/src/state/immutable-trie/trie.go:313 +0x2ea
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Txn).Lookup(0xc047fdaa60, {0xc042fb5560, 0xc00006ed80, 0xc042fb5560})
	/go/src/state/immutable-trie/trie.go:262 +0x5b
github.com/dogechain-lab/dogechain/state/immutable-trie.(*Trie).Get(0xc00edf6b48, {0xc042fb5560, 0x413e370, 0xc00edf6a80})
	/go/src/state/immutable-trie/trie.go:105 +0x74
github.com/dogechain-lab/dogechain/state.(*StateObject).GetCommitedState(0xc00f05bec0, {0x14, 0x7, 0xac, 0x76, 0x1f, 0x93, 0x1f, 0xb7, 0x7a, ...})
	/go/src/state/state.go:131 +0xa4
github.com/dogechain-lab/dogechain/state.(*Txn).GetState(0xc0fa98e1b171005b, {0x10, 0xed, 0x1a, 0x8b, 0x2e, 0x90, 0x8b, 0xdd, 0x45, ...}, ...)
	/go/src/state/txn.go:365 +0x2a8
github.com/dogechain-lab/dogechain/state.(*Transition).GetStorage(0x20, {0x10, 0xed, 0x1a, 0x8b, 0x2e, 0x90, 0x8b, 0xdd, 0x45, ...}, ...)
	/go/src/state/executor.go:826 +0x7a
github.com/dogechain-lab/dogechain/state/runtime/evm.opSload(0xc047145320)
	/go/src/state/runtime/evm/instructions.go:481 +0x16c
github.com/dogechain-lab/dogechain/state/runtime/evm.(*state).Run(0xc047145320)
	/go/src/state/runtime/evm/state.go:245 +0x110
github.com/dogechain-lab/dogechain/state/runtime/evm.(*EVM).Run(0x6737740, 0xc00e58d3f0, {0x58ccde0, 0xc049fd6700}, 0xc049fd6730)
	/go/src/state/runtime/evm/evm.go:45 +0x15f
github.com/dogechain-lab/dogechain/state.(*Transition).run(0xc049fd6700, 0xb7dfd3f7c127e104, {0x58ccde0, 0xc049fd6700})
	/go/src/state/executor.go:632 +0x16f
github.com/dogechain-lab/dogechain/state.(*Transition).applyCall(0xc049fd6700, 0xc00e58d3f0, 0x0, {0x58ccde0, 0xc049fd6700})
	/go/src/state/executor.go:685 +0x2b3
github.com/dogechain-lab/dogechain/state.(*Transition).Callx(0xc039078a20, 0xf1, {0x58ccde0, 0xc049fd6700})
	/go/src/state/executor.go:855 +0x45
github.com/dogechain-lab/dogechain/state/runtime/evm.opCall.func1(0xc039078a20)
	/go/src/state/runtime/evm/instructions.go:1162 +0x2a4
github.com/dogechain-lab/dogechain/state/runtime/evm.(*state).Run(0xc039078a20)
	/go/src/state/runtime/evm/state.go:245 +0x110
github.com/dogechain-lab/dogechain/state/runtime/evm.(*EVM).Run(0x6737740, 0xc00e58d340, {0x58ccde0, 0xc049fd6700}, 0xc049fd6730)
	/go/src/state/runtime/evm/evm.go:45 +0x15f
github.com/dogechain-lab/dogechain/state.(*Transition).run(0xc049fd6700, 0xf4910367dd938a4d, {0x58ccde0, 0xc049fd6700})
	/go/src/state/executor.go:632 +0x16f
github.com/dogechain-lab/dogechain/state.(*Transition).applyCall(0xc049fd6700, 0xc00e58d340, 0x0, {0x58ccde0, 0xc049fd6700})
	/go/src/state/executor.go:685 +0x2b3
github.com/dogechain-lab/dogechain/state.(*Transition).Call2(0xc049fd6700, {0x6e, 0x72, 0xbc, 0x5f, 0x52, 0x40, 0x9a, 0x9d, 0x4d, ...}, ...)
	/go/src/state/executor.go:626 +0x265
github.com/dogechain-lab/dogechain/state.(*Transition).apply(0xc049fd6700, 0xc02ae6b7c0)
	/go/src/state/executor.go:585 +0xd0c
github.com/dogechain-lab/dogechain/state.(*Transition).Apply(0xc049fd6700, 0x6737740)
	/go/src/state/executor.go:394 +0x133
github.com/dogechain-lab/dogechain/state.(*Transition).Write(0xc049fd6700, 0xc010b60d20)
	/go/src/state/executor.go:253 +0x15d
github.com/dogechain-lab/dogechain/state.(*Executor).ProcessBlock(0x51f8520, {0x60, 0xeb, 0x1, 0xc6, 0x95, 0xe6, 0x61, 0x97, 0x38, ...}, ...)
	/go/src/state/executor.go:113 +0x107
github.com/dogechain-lab/dogechain/blockchain.(*Blockchain).executeBlockTransactions(0xc0000d2840, 0xc04c532f00)
	/go/src/blockchain/blockchain.go:847 +0x149
github.com/dogechain-lab/dogechain/blockchain.(*Blockchain).verifyBlockBody(0xc0000d2840, 0xc04c532f00)
	/go/src/blockchain/blockchain.go:792 +0x125
github.com/dogechain-lab/dogechain/blockchain.(*Blockchain).verifyBlock(0xc000f72c60, 0xc04c532f00)
	/go/src/blockchain/blockchain.go:706 +0x3c
github.com/dogechain-lab/dogechain/blockchain.(*Blockchain).VerifyFinalizedBlock(0xc0000d2840, 0xc04c532f00)
	/go/src/blockchain/blockchain.go:685 +0xa7
github.com/dogechain-lab/dogechain/protocol.(*Syncer).BulkSyncWithPeer(0xc00056e300, 0xc01925ea10, 0xc03c20e0c0)
	/go/src/protocol/syncer.go:619 +0x5b8
github.com/dogechain-lab/dogechain/consensus/ibft.(*Ibft).runSyncState(0xc000f72c60)
	/go/src/consensus/ibft/ibft.go:505 +0x144
github.com/dogechain-lab/dogechain/consensus/ibft.(*Ibft).runCycle(0xaf636)
	/go/src/consensus/ibft/ibft.go:440 +0x1dd
github.com/dogechain-lab/dogechain/consensus/ibft.(*Ibft).start(0xc000f72c60)
	/go/src/consensus/ibft/ibft.go:417 +0xe5
created by github.com/dogechain-lab/dogechain/consensus/ibft.(*Ibft).Start
	/go/src/consensus/ibft/ibft.go:221 +0x1c9

@DarianShawn DarianShawn added the bug fix Functionality that fixes a bug label Sep 21, 2022
@DarianShawn DarianShawn added this to the Release 1.1.4 milestone Sep 21, 2022
@DarianShawn DarianShawn self-assigned this Sep 21, 2022
Copy link

@0xcb9ff9 0xcb9ff9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DarianShawn DarianShawn merged commit c648f03 into dev Sep 22, 2022
@DarianShawn DarianShawn deleted the fix/panic-when-close-kvstorage branch September 22, 2022 12:28
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fix Functionality that fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants