-
Notifications
You must be signed in to change notification settings - Fork 1
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
Clean Read Only Geth #2
base: master
Are you sure you want to change the base?
Conversation
core/rawdb: do prefixed lookup first
When talking to an HTTP2 server, there are situations where it needs to "rewind" the Request.Body. To allow this, we have to set up the Request.GetBody function to return a brand new instance of the body. If not set, we can end up with the following error: http2: Transport: cannot retry err [http2: Transport received Server's graceful shutdown GOAWAY] after Request.Body was written; define Request.GetBody to avoid this error See this commit for more information: https://sourcegraph.com/github.com/golang/net/-/commit/cffdcf672aee934982473246bc7e9a8ba446aa9b?visible=2
// Try with the legacy code scheme first, if not then try with current | ||
// scheme. Since most of the code will be found with legacy scheme. | ||
// | ||
// todo(rjl493456442) change the order when we forcibly upgrade the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you need this change, and are we sure it's safe?
eth/backend.go
Outdated
genesisHash = common.Hash{} | ||
genesisErr = nil | ||
} else { | ||
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the database cannot be opened read-only with a freezer, why does OpenDatabaesWithFreezer
have a readonly
arg? Please comment this for the reader.
eth/backend.go
Outdated
if s.config.LightServ > 0 { | ||
if s.config.LightPeers >= s.p2pServer.MaxPeers { | ||
return fmt.Errorf("invalid peer config: light peer count (%d) >= total peer count (%d)", s.config.LightPeers, s.p2pServer.MaxPeers) | ||
if s.readOnly { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be !s.readOnly
?
if !s.readOnly { | ||
// Stop all the peer-related stuff first. | ||
s.ethDialCandidates.Close() | ||
s.snapDialCandidates.Close() | ||
s.handler.Stop() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is easy to code, but it'd be nice not to branch on !s.readOnly
in particular, but rather have the Close()
/Stop()
functions handle a never-opened/never-started case more gracefully.
Analogous to how the destructor of a unique_ptr just does the right thing even if the unique_ptr is null.
// Creates an empty AccountManager with no backends. Callers (e.g. cmd/geth) | ||
// are required to add the backends later on. | ||
node.accman = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try to keep all the !node.readOnly
logic contained in fewer if
blocks? It seems like we could merge above and below, if this assignment was moved up?
@@ -342,50 +352,52 @@ func (n *Node) startRPC() error { | |||
if err := n.startInProc(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner to easier to rename this function startExternalRPC
, remove n.startInProc()
from it entirely, and avoid extra layer of branching on !n.readOnly
.
Overall: You have a lot of if !n.readOnly
branches, which is a bad code smell -- try to refactor the code so that the read-only special case is self-contained.
@@ -396,9 +408,11 @@ func (n *Node) wsServerForPort(port int) *httpServer { | |||
} | |||
|
|||
func (n *Node) stopRPC() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above, I think this should be stopExternalRPC
.
node/node.go
Outdated
n.http.stop() | ||
n.ws.stop() | ||
n.ipc.stop() | ||
if !n.readOnly { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and elsewhere, you're conflating "read-only" with "used-as-a-library" in a few places. You could imagine starting HTTP/WS/IPC services on a read-only geth process. Maybe localLibrary
should be a separate option in Node?
And readOnlyGeth/
should be renamed readOnlyLib/
?
* tests: add ipsilon/evm-benchmarks git submodule * tests: plug-in evm-benchmarks
* eth/tracers: add initial native prestate tracer * fix balance hex * handle prestate for tx from and to * drop created contract from prestate * fix sender balance * use switch instead Co-authored-by: Martin Holst Swende <[email protected]> * minor fix * lookup create2 account * mv code around a bit * check stackLen for create2 * fix transfer tx for js prestate tracer * fix create2 addr * track extcodehash in js prestate tracer Co-authored-by: Martin Holst Swende <[email protected]>
* build: append GOARM to arm lint download URL otherwise it fails with: downloading from https://github.com/golangci/golangci-lint/releases/download/v1.42.0/golangci-lint-1.42.0-linux-arm.tar.gz ci.go:347: download error: status 404 * build: increase timeout for lint Otherwise it times out on a pi * Increase timeout even further saw longer build times
* all: seperate catalyst package * eth/catalyst: moved some methods, added docs * eth/catalyst, les/catalyst: add method docs * core, eth, les, miner: move common function to beacon package * eth/catalyst: goimported * cmd/utils, miner/stress/beacon: naming nitpicks Co-authored-by: Marius van der Wijden <[email protected]> Co-authored-by: Péter Szilágyi <[email protected]>
I believe the sentence is attempting to explain that the URL is "[used] by upper layers to define a sorting order over all wallets from multiple backends."
* eth/tracers: clean-up tracer collection * Rm test for dropped tracer
This change makes it so WaitMined no longer logs an error when the receipt is unavailable. It also changes the simulated backend to return NotFound for unavailable receipts, just like ethclient does.
cmd: auto-enable beacon APIs if TTD is defined
This also contains some changes to the protocol handler to make the tests pass.
In this PR, I removed the
readOnlyNode
andreadOnlyBackend
. Instead, I used a boolean variable to represent whether it's in thereadOnly
mode to make the code cleaner.