Skip to content

core/state: copy trie too, not just content#15549

Merged
karalabe merged 1 commit into
ethereum:masterfrom
karalabe:statedb-copy
Nov 24, 2017
Merged

core/state: copy trie too, not just content#15549
karalabe merged 1 commit into
ethereum:masterfrom
karalabe:statedb-copy

Conversation

@karalabe
Copy link
Copy Markdown
Member

When copying the statedb (used by the RPC to access the pending state), we have not copied the trie, only the state objects. This means that if the RPC would have modified the state, it would have corrupted the miner. This does not happen currently (AFAIK).

We need this fix in for concurrent block tracing with shared statedbs.

@karalabe karalabe added this to the 1.8.0 milestone Nov 24, 2017
@karalabe karalabe requested a review from holiman November 24, 2017 09:22
@holiman
Copy link
Copy Markdown
Contributor

holiman commented Nov 24, 2017

I'm thinking maybe it would be worth to have a testcase about this? To ensure that future changes does not break this, and that the copy mechanism is sufficiently deep.

@karalabe
Copy link
Copy Markdown
Member Author

@holiman I've added a test that panics without the copy fix. PTAL.

=== RUN   TestCopy
fatal error: concurrent map writes

goroutine 24 [running]:
runtime.throw(0x84d32c, 0x15)
	/opt/google/go/src/runtime/panic.go:605 +0x95 fp=0xc420055af0 sp=0xc420055ad0 pc=0x42deb5
runtime.mapassign_faststr(0x7d7c60, 0xc4203c47e0, 0xc4201d9280, 0x20, 0xc4201d9280)
	/opt/google/go/src/runtime/hashmap_fast.go:607 +0x4f5 fp=0xc420055b70 sp=0xc420055af0 pc=0x40f295
github.com/ethereum/go-ethereum/trie.(*SecureTrie).TryUpdate(0xc4202d8420, 0xc4201d9200, 0x14, 0x14, 0xc4204a5ef0, 0x48, 0x48, 0x0, 0x0)
	/work/src/github.com/ethereum/go-ethereum/trie/secure_trie.go:113 +0x1f5 fp=0xc420055c00 sp=0xc420055b70 pc=0x6de655
github.com/ethereum/go-ethereum/core/state.(*StateDB).updateStateObject(0xc4202b2000, 0xc420554e00)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb.go:338 +0x10c fp=0xc420055cc0 sp=0xc420055c00 pc=0x748ebc
github.com/ethereum/go-ethereum/core/state.(*StateDB).Finalise(0xc4202b2000, 0x85fa01)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb.go:524 +0x163 fp=0xc420055d80 sp=0xc420055cc0 pc=0x74b303
github.com/ethereum/go-ethereum/core/state.TestCopy(0xc4202b20f0)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb_test.go:154 +0x65b fp=0xc420055fa8 sp=0xc420055d80 pc=0x752feb
testing.tRunner(0xc4202b20f0, 0x85faa8)
	/opt/google/go/src/testing/testing.go:746 +0xd0 fp=0xc420055fd0 sp=0xc420055fa8 pc=0x4e88d0
runtime.goexit()
	/opt/google/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420055fd8 sp=0xc420055fd0 pc=0x45e3d1
created by testing.(*T).Run
	/opt/google/go/src/testing/testing.go:789 +0x2de

goroutine 1 [chan receive]:
testing.(*T).Run(0xc420104000, 0x8487f7, 0x8, 0x85faa8, 0x47da01)
	/opt/google/go/src/testing/testing.go:790 +0x2fc
testing.runTests.func1(0xc420104000)
	/opt/google/go/src/testing/testing.go:1004 +0x64
testing.tRunner(0xc420104000, 0xc420057de0)
	/opt/google/go/src/testing/testing.go:746 +0xd0
testing.runTests(0xc4200e0ec0, 0xc3ba40, 0x14, 0x14, 0x0)
	/opt/google/go/src/testing/testing.go:1002 +0x2d8
testing.(*M).Run(0xc420057f18, 0xc420057f70)
	/opt/google/go/src/testing/testing.go:921 +0x111
main.main()
	github.com/ethereum/go-ethereum/core/state/_test/_testmain.go:82 +0xdb

goroutine 51 [runnable]:
github.com/ethereum/go-ethereum/core/state.(*StateDB).updateStateObject(0xc4202b22d0, 0xc4204e29a0)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb.go:332 +0x282
github.com/ethereum/go-ethereum/core/state.(*StateDB).Finalise(0xc4202b22d0, 0x890d01)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb.go:524 +0x163
github.com/ethereum/go-ethereum/core/state.TestCopy.func1(0xc4202b22d0, 0xc4202c0060)
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb_test.go:151 +0x30
created by github.com/ethereum/go-ethereum/core/state.TestCopy
	/work/src/github.com/ethereum/go-ethereum/core/state/statedb_test.go:150 +0x645
exit status 2
FAIL	github.com/ethereum/go-ethereum/core/state	0.135s

@karalabe karalabe merged commit de37e08 into ethereum:master Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants