Skip to content

Commit

Permalink
fix txs p2p && testnet scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
FletcherMan committed May 23, 2023
1 parent 8edec7f commit 69cf63f
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ profile.cov
/dashboard/assets/package-lock.json

**/yarn-error.log
/build/db*/
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ devtools:
env GOBIN= go install ./cmd/abigen
@type "solc" 2> /dev/null || echo 'Please install solc'
@type "protoc" 2> /dev/null || echo 'Please install protoc'


testnet-up:
docker-compose -f testnet/docker-compose.yml up -d
.PHONY: testnet-up

testnet-down:
docker-compose -f testnet/docker-compose.yml down
.PHONY: testnet-down

testnet-clean:
docker-compose -f testnet/docker-compose.yml down
docker images -q morphism_geth:latest | xargs -r docker rmi
docker volume ls --filter "name=morph_data*" -q | xargs -r docker volume rm
.PHONY: testnet-clean
6 changes: 4 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,10 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
// setBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
var urls []string
switch {
case ctx.GlobalIsSet(MainnetFlag.Name):
urls = params.MainnetBootnodes
case ctx.GlobalIsSet(BootnodesFlag.Name):
urls = SplitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
case ctx.GlobalBool(RopstenFlag.Name):
Expand All @@ -891,7 +893,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.GoerliBootnodes
case ctx.GlobalBool(ScrollAlphaFlag.Name):
urls = params.ScrollAlphaBootnodes
case cfg.BootstrapNodes != nil:
case cfg.BootstrapNodes != nil || len(urls) == 0:
return // already set, don't apply defaults.
}

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ services:
entrypoint: # pass the L2 specific flags by overriding the entry-point and adding extra arguments
- "/bin/sh"
- "/entrypoint.sh"
- "--authrpc.jwtsecret=/config/test-jwt-secret.txt"

19 changes: 15 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GETH_DATA_DIR=/db
GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth"
GETH_CHAINDATA_DIR="$GETH_DATA_DIR/geth/chaindata"
GENESIS_FILE_PATH="${GENESIS_FILE_PATH:-/genesis.json}"

DEFAULE_MINER_ETHERBASE="0x0e87cd091e091562F25CB1cf4641065dA2C049F5"

if [[ ! -e "$GETH_CHAINDATA_DIR" ]]; then
echo "$GETH_CHAINDATA_DIR missing, running init"
Expand All @@ -11,8 +11,15 @@ else
echo "$GETH_KEYSTORE_DIR exists."
fi

if [[ -z "$MINER_ETHERBASE" ]]; then
# the environment variable is missing, set a default value
MINER_ETHERBASE=$DEFAULE_MINER_ETHERBASE
fi

optional_bootnodes=${BOOT_NODES:+"--bootnodes=$BOOT_NODES"}

geth \
# shellcheck disable=SC2125
COMMAND="geth \
--datadir="$GETH_DATA_DIR" \
--verbosity=3 \
--http \
Expand All @@ -26,4 +33,8 @@ geth \
--authrpc.port="8551" \
--authrpc.vhosts="*" \
--authrpc.jwtsecret=/config/jwt-secret.txt \
--gcmode=archive
--gcmode=archive \
--mine \
--miner.etherbase=$MINER_ETHERBASE $optional_bootnodes"

$COMMAND
12 changes: 0 additions & 12 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,6 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
if etherbase != (common.Address{}) {
return etherbase, nil
}
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
etherbase := accounts[0].Address

s.lock.Lock()
s.etherbase = etherbase
s.lock.Unlock()

log.Info("Etherbase automatically configured", "address", etherbase)
return etherbase, nil
}
}
return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
}

Expand Down
37 changes: 20 additions & 17 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,29 +1068,32 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
// commit runs any post-transaction state modifications, assembles the final block
// and commits new work if consensus engine is running.
func (w *worker) commit(uncles []*types.Header, interval func(), update bool, start time.Time) error {
// Deep copy receipts here to avoid interaction between different tasks.
receipts := copyReceipts(w.current.receipts)
s := w.current.state.Copy()
block, err := w.engine.FinalizeAndAssemble(w.chain, w.current.header, s, w.current.txs, uncles, receipts)
if err != nil {
return err
}
if w.isRunning() {
if interval != nil {
interval()
}
select {
case w.taskCh <- &task{receipts: receipts, state: s, block: block, createdAt: time.Now()}:
w.unconfirmed.Shift(block.NumberU64() - 1)
log.Info("Commit new mining work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
"uncles", len(uncles), "txs", w.current.tcount,
"gas", block.GasUsed(), "fees", totalFees(block, receipts),
"elapsed", common.PrettyDuration(time.Since(start)))

case <-w.exitCh:
log.Info("Worker has exited")
// Deep copy receipts here to avoid interaction between different tasks.
receipts := copyReceipts(w.current.receipts)
s := w.current.state.Copy()
_, err := w.engine.FinalizeAndAssemble(w.chain, w.current.header, s, w.current.txs, uncles, receipts)
if err != nil {
return err
}

// ignore it, as Morphism has its own consensus
//select {
//case w.taskCh <- &task{receipts: receipts, state: s, block: block, createdAt: time.Now()}:
// w.unconfirmed.Shift(block.NumberU64() - 1)
// log.Info("Commit new mining work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
// "uncles", len(uncles), "txs", w.current.tcount,
// "gas", block.GasUsed(), "fees", totalFees(block, receipts),
// "elapsed", common.PrettyDuration(time.Since(start)))
//
//case <-w.exitCh:
// log.Info("Worker has exited")
//}
}

if update {
w.updateSnapshot()
}
Expand Down
96 changes: 96 additions & 0 deletions testnet/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
version: '3.4'

volumes:
morph_data_0:
morph_data_1:
morph_data_2:
morph_data_3:

services:
morph-geth-0:
build:
context: ..
dockerfile: ./Dockerfile
image: morphism_geth:latest
ports:
- "8545:8545"
- "8546:8546"
- "8551:8551"
- "30303"
volumes:
- "morph_data_0:/db"
- "${PWD}/build/jwt-secret.txt:/config/jwt-secret.txt"
- "${PWD}/genesis_l2.json:/genesis.json"
- "${PWD}/testnet/nodekey:/db/geth/nodekey"
entrypoint: # always use this nodekey, in order to keep the encoded node ID the same
- "/bin/sh"
- "/entrypoint.sh"

morph-geth-1:
depends_on:
- morph-geth-0
build:
context: ..
dockerfile: ./Dockerfile
image: morphism_geth:latest
ports:
- "8645:8545"
- "8646:8546"
- "8651:8551"
- "30303"
volumes:
- "morph_data_1:/db"
- "${PWD}/build/jwt-secret.txt:/config/jwt-secret.txt"
- "${PWD}/genesis_l2.json:/genesis.json"
- "${PWD}/testnet/static-nodes.json:/db/geth/static-nodes.json"
environment:
- BOOT_NODES=enode://58e698ea2dd8a76e0cb185d13c1faabf223b60c89fef988c8b89496571056d6c2922109537bb291cd87f2ec09a23ac37d59bde2c7a4885d07b7b641cadff2921@morph-geth-0:30303
entrypoint: # pass the L2 specific flags by overriding the entry-point and adding extra arguments
- "/bin/sh"
- "/entrypoint.sh"

morph-geth-2:
depends_on:
- morph-geth-0
build:
context: ..
dockerfile: ./Dockerfile
image: morphism_geth:latest
ports:
- "8745:8545"
- "8746:8546"
- "8751:8551"
- "30303"
volumes:
- "morph_data_2:/db"
- "${PWD}/build/jwt-secret.txt:/config/jwt-secret.txt"
- "${PWD}/genesis_l2.json:/genesis.json"
- "${PWD}/testnet/static-nodes.json:/db/geth/static-nodes.json"
environment:
- BOOT_NODES=enode://58e698ea2dd8a76e0cb185d13c1faabf223b60c89fef988c8b89496571056d6c2922109537bb291cd87f2ec09a23ac37d59bde2c7a4885d07b7b641cadff2921@morph-geth-0:30303
entrypoint: # pass the L2 specific flags by overriding the entry-point and adding extra arguments
- "/bin/sh"
- "/entrypoint.sh"

morph-geth-3:
depends_on:
- morph-geth-0
build:
context: ..
dockerfile: ./Dockerfile
image: morphism_geth:latest
ports:
- "8845:8545"
- "8846:8546"
- "8851:8551"
- "30303"
volumes:
- "morph_data_3:/db"
- "${PWD}/build/jwt-secret.txt:/config/jwt-secret.txt"
- "${PWD}/genesis_l2.json:/genesis.json"
- "${PWD}/testnet/static-nodes.json:/db/geth/static-nodes.json"
environment:
- BOOT_NODES=enode://58e698ea2dd8a76e0cb185d13c1faabf223b60c89fef988c8b89496571056d6c2922109537bb291cd87f2ec09a23ac37d59bde2c7a4885d07b7b641cadff2921@morph-geth-0:30303
entrypoint: # pass the L2 specific flags by overriding the entry-point and adding extra arguments
- "/bin/sh"
- "/entrypoint.sh"
1 change: 1 addition & 0 deletions testnet/nodekey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
780fafe70f0c15a0a79beeaf19e32bde4caff7a625e8bbcf6c64bffd1df54c2f
1 change: 1 addition & 0 deletions testnet/static-nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["enode://58e698ea2dd8a76e0cb185d13c1faabf223b60c89fef988c8b89496571056d6c2922109537bb291cd87f2ec09a23ac37d59bde2c7a4885d07b7b641cadff2921@morph-geth-0:30303"]

0 comments on commit 69cf63f

Please sign in to comment.