Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'ledgerwatch:devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKrishna authored Jul 29, 2022
2 parents 3a65b19 + a862bd9 commit 944fd4f
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 120 deletions.
6 changes: 3 additions & 3 deletions DEV_CHAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If evereything is fine, by changing directory to erigon/build/bin you will see t
On the terminal you can type the following command to start node1.

```bash
./erigon --datadir=dev --chain dev --private.api.addr=localhost:9090 --mine
./erigon --datadir=dev --chain=dev --private.api.addr=localhost:9090 --mine
```

Argument notes:
Expand Down Expand Up @@ -63,8 +63,8 @@ To tell Node 2 where Node 1 is we will use the Enode info of Node 1 we saved bef
Open terminal 3 and navigate to erigon/build/bin folder. Paste in the following command the Enode info and run it, be careful to remove the last part ?discport=0.

```bash
./erigon --datadir=dev2 --chain dev --private.api.addr=localhost:9091 \
--staticpeers "enode://d30d079163d7b69fcb261c0538c0c3faba4fb4429652970e60fa25deb02a789b4811e98b468726ba0be63b9dc925a019f433177eb6b45c23bb78892f786d8f7a@127.0.0.1:53171" \
./erigon --datadir=dev2 --chain=dev --private.api.addr=localhost:9091 \
--staticpeers="enode://d30d079163d7b69fcb261c0538c0c3faba4fb4429652970e60fa25deb02a789b4811e98b468726ba0be63b9dc925a019f433177eb6b45c23bb78892f786d8f7a@127.0.0.1:53171" \
--nodiscover
```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ make erigon
./build/bin/erigon
```

Default `--snapshots=true` for `mainnet`, `goerli`, `bsc`. Other networks now have default `--snapshots=false`. Increase download speed by flag `--torrent.download.rate=20mb`. <code>🔬 See [Downloader docs](./cmd/downloader/readme.md)</code>
Default `--snapshots` for `mainnet`, `goerli`, `bsc`. Other networks now have default `--snapshots=false`. Increase download speed by flag `--torrent.download.rate=20mb`. <code>🔬 See [Downloader docs](./cmd/downloader/readme.md)</code>

Use `--datadir` to choose where to store data.

Expand Down Expand Up @@ -106,7 +106,7 @@ of the public testnets, Görli. It syncs much quicker, and does not take so much
git clone --recurse-submodules -j8 https://github.com/ledgerwatch/erigon.git
cd erigon
make erigon
./build/bin/erigon --datadir goerli --chain goerli
./build/bin/erigon --datadir=<your_datadir> --chain=goerli
```

Please note the `--datadir` option that allows you to store Erigon files in a non-default location, in this example,
Expand Down
2 changes: 1 addition & 1 deletion RELEASE_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ until which we have manually checked the usefulness of the Jump dest code bitmap
commands:
````
make state
./build/bin/state checkChangeSets --datadir <path to datadir> --block <value of MainnetNotCheckedFrom>
./build/bin/state checkChangeSets --datadir=<path to datadir> --block=<value of MainnetNotCheckedFrom>
````
If there are any transactions where code bitmap was useful, warning messages like this will be displayed:
````
Expand Down
159 changes: 110 additions & 49 deletions TESTING.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions cmd/downloader/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Service to seed/download historical data (snapshots, immutable .seg files) by Bi
As many other Erigon components (txpool, sentry, rpc daemon) it may be built-into Erigon or run as separated process.

```shell
# 1. Downloader by default run inside Erigon, by `--snapshots=true` flag:
erigon --snapshots=true --datadir=<your_datadir>
# 1. Downloader by default run inside Erigon, by `--snapshots` flag:
erigon --snapshots --datadir=<your_datadir>
```

```shell
# 2. It's possible to start Downloader as independent process, by `--snapshots=true --downloader.api.addr=127.0.0.1:9093` flags:
# 2. It's possible to start Downloader as independent process, by `--snapshots --downloader.api.addr=127.0.0.1:9093` flags:
make erigon downloader

# Start downloader (can limit network usage by 512mb/sec: --torrent.download.rate=512mb --torrent.upload.rate=512mb)
Expand All @@ -21,7 +21,7 @@ downloader --downloader.api.addr=127.0.0.1:9093 --torrent.port=42068 --datadir=<
# --torrent.port=42068 - is for public BitTorrent protocol listen

# Erigon on startup does send list of .torrent files to Downloader and wait for 100% download accomplishment
erigon --snapshots=true --downloader.api.addr=127.0.0.1:9093 --datadir=<your_datadir>
erigon --snapshots --downloader.api.addr=127.0.0.1:9093 --datadir=<your_datadir>
```

Use `--snap.keepblocks=true` to don't delete retired blocks from DB
Expand All @@ -32,7 +32,7 @@ Any network/chain can start with snapshot sync:
- node will move old blocks from DB to snapshots of 1K blocks size, then merge snapshots to bigger range, until
snapshots of 500K blocks, then automatically start seeding new snapshot

Flag `--snapshots=true` is compatible with `--prune` flag
Flag `--snapshots` is compatible with `--prune` flag

## How to create new network or bootnode

Expand All @@ -50,7 +50,7 @@ downloader torrent_hashes --rebuild --datadir=<your_datadir>
# Start downloader (seeds automatically)
downloader --downloader.api.addr=127.0.0.1:9093 --datadir=<your_datadir>

# Erigon is not required for snapshots seeding. But Erigon with --snapshots=true also does seeding.
# Erigon is not required for snapshots seeding. But Erigon with --snapshots also does seeding.
```

Additional info:
Expand Down
7 changes: 7 additions & 0 deletions cmd/rpcdaemon/commands/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutil.By
return common.Hash{}, err
}

txnChainId := txn.GetChainID()
chainId := api._chainConfig.ChainID

if chainId.Cmp(txnChainId.ToBig()) != 0 {
return common.Hash{}, fmt.Errorf("invalid chain id, expected: %d got: %d", chainId, *txnChainId)
}

// If the transaction fee cap is already specified, ensure the
// fee of the given transaction is _reasonable_.
if err := checkTxFee(txn.GetPrice().ToBig(), txn.GetGas(), ethconfig.Defaults.RPCTxFeeCap); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions cmd/rpcdaemon22/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ func (e *EngineImpl) ExchangeTransitionConfigurationV1(ctx context.Context, beac
}

terminalTotalDifficulty := chainConfig.TerminalTotalDifficulty

if terminalTotalDifficulty == nil {
return TransitionConfiguration{}, fmt.Errorf("the execution layer doesn't have a terminal total difficulty. expected: %v", beaconConfig.TerminalTotalDifficulty)
}

if terminalTotalDifficulty.Cmp((*big.Int)(beaconConfig.TerminalTotalDifficulty)) != 0 {
if terminalTotalDifficulty != nil && terminalTotalDifficulty.Cmp((*big.Int)(beaconConfig.TerminalTotalDifficulty)) != 0 {
return TransitionConfiguration{}, fmt.Errorf("the execution layer has a wrong terminal total difficulty. expected %v, but instead got: %d", beaconConfig.TerminalTotalDifficulty, terminalTotalDifficulty)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/sentry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ combined). Ethereum mainnet configuration is currently hard-coded.
```

```
./buid/bin/sentry --datadir <sentry_datadir>
./buid/bin/sentry --datadir=<sentry_datadir>
```

The command above specifies `--datadir` option - directory where the database files will be written (it doesn't need access to Erion's datadir). These two options
Expand All @@ -25,7 +25,7 @@ p2p sentry running on the same computer listening to the port `9091`. In order t
computer, or a different port (or both), the option `--sentry.api.addr` can be used. For example:

```
./buid/bin/sentry --datadir <sentry_datadir> --sentry.api.addr localhost:9999
./buid/bin/sentry --datadir=<sentry_datadir> --sentry.api.addr=localhost:9999
```

The command above will expect the p2p sentry running on the same computer, but on the port `9999`
Expand Down
2 changes: 1 addition & 1 deletion cmd/sentry/sentry/sentry_multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (cs *MultiClient) newBlock66(ctx context.Context, inreq *proto_sentry.Inbou
func (cs *MultiClient) blockBodies66(inreq *proto_sentry.InboundMessage, _ direct.SentryClient) error {
var request eth.BlockRawBodiesPacket66
if err := rlp.DecodeBytes(inreq.Data, &request); err != nil {
return fmt.Errorf("decode BlockBodiesPacket66: %w", err)
return fmt.Errorf("decode BlockBodiesPacket66: %w, data: %x", err, inreq.Data)
}
txs, uncles := request.BlockRawBodiesPacket.Unpack()
cs.Bd.DeliverBodies(&txs, &uncles, uint64(len(inreq.Data)), ConvertH512ToPeerID(inreq.PeerId))
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ var (
}
RpcStreamingDisableFlag = cli.BoolFlag{
Name: "rpc.streaming.disable",
Usage: "Erigon has enalbed json streamin for some heavy endpoints (like trace_*). It's treadoff: greatly reduce amount of RAM (in some cases from 30GB to 30mb), but it produce invalid json format if error happened in the middle of streaming (because json is not streaming-friendly format)",
Usage: "Erigon has enalbed json streaming for some heavy endpoints (like trace_*). It's treadoff: greatly reduce amount of RAM (in some cases from 30GB to 30mb), but it produce invalid json format if error happened in the middle of streaming (because json is not streaming-friendly format)",
}
HTTPTraceFlag = cli.BoolFlag{
Name: "http.trace",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20220728074713-fadc9b21d1dd
github.com/ledgerwatch/erigon-lib v0.0.0-20220729020228-73ce1c43eaa7
github.com/ledgerwatch/erigon-snapshot v1.0.0
github.com/ledgerwatch/log/v3 v3.4.1
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20220728074713-fadc9b21d1dd h1:N8Erhb3TNWyXBFYZD6tthmDaIhwWN4bVoATuoxJuSpA=
github.com/ledgerwatch/erigon-lib v0.0.0-20220728074713-fadc9b21d1dd/go.mod h1:19wwSb5qbagorz9a4QN9FzNqSPjmOJkwa5TezGjloks=
github.com/ledgerwatch/erigon-lib v0.0.0-20220729020228-73ce1c43eaa7 h1:4yqgpRL2pJCrod0juCMepUMiXr10MKSASCBzxoUE7bw=
github.com/ledgerwatch/erigon-lib v0.0.0-20220729020228-73ce1c43eaa7/go.mod h1:19wwSb5qbagorz9a4QN9FzNqSPjmOJkwa5TezGjloks=
github.com/ledgerwatch/erigon-snapshot v1.0.0 h1:bp/7xoPdM5lK7LFdqEMH008RZmqxMZV0RUVEQiWs7v4=
github.com/ledgerwatch/erigon-snapshot v1.0.0/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.4.1 h1:/xGwlVulXnsO9Uq+tzaExc8OWmXXHU0dnLalpbnY5Bc=
Expand Down
92 changes: 46 additions & 46 deletions rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -458,58 +459,57 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage, stream *jso

// runMethod runs the Go callback for an RPC method.
func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *callback, args []reflect.Value, stream *jsoniter.Stream) *jsonrpcMessage {
if callb.streamable {
stream.WriteObjectStart()
stream.WriteObjectField("jsonrpc")
stream.WriteString("2.0")
stream.WriteMore()
if msg.ID != nil {
stream.WriteObjectField("id")
stream.Write(msg.ID)
stream.WriteMore()
}
stream.WriteObjectField("result")
_, err := callb.call(ctx, msg.Method, args, stream)
if err != nil {
return msg.errorResponse(err)
/*
stream.WriteMore()
stream.WriteObjectField("error")
stream.WriteObjectStart()
stream.WriteObjectField("code")
ec, ok := err.(Error)
if ok {
stream.WriteInt(ec.ErrorCode())
} else {
stream.WriteInt(defaultErrorCode)
}
stream.WriteMore()
stream.WriteObjectField("message")
stream.WriteString(fmt.Sprintf("%v", err))
de, ok := err.(DataError)
if ok {
stream.WriteMore()
stream.WriteObjectField("data")
data, derr := json.Marshal(de.ErrorData())
if derr == nil {
stream.Write(data)
} else {
stream.WriteString(fmt.Sprintf("%v", derr))
}
}
stream.WriteObjectEnd()
*/
}
stream.WriteObjectEnd()
stream.Flush()
return nil
} else {
if !callb.streamable {
result, err := callb.call(ctx, msg.Method, args, stream)
if err != nil {
return msg.errorResponse(err)
}
return msg.response(result)
}

stream.WriteObjectStart()
stream.WriteObjectField("jsonrpc")
stream.WriteString("2.0")
stream.WriteMore()
if msg.ID != nil {
stream.WriteObjectField("id")
stream.Write(msg.ID)
stream.WriteMore()
}
stream.WriteObjectField("result")
_, err := callb.call(ctx, msg.Method, args, stream)
if err != nil {
//return msg.errorResponse(err)

stream.WriteMore()
stream.WriteObjectField("error")
stream.WriteObjectStart()
stream.WriteObjectField("code")
ec, ok := err.(Error)
if ok {
stream.WriteInt(ec.ErrorCode())
} else {
stream.WriteInt(defaultErrorCode)
}
stream.WriteMore()
stream.WriteObjectField("message")
stream.WriteString(fmt.Sprintf("%v", err))
de, ok := err.(DataError)
if ok {
stream.WriteMore()
stream.WriteObjectField("data")
data, derr := json.Marshal(de.ErrorData())
if derr == nil {
stream.Write(data)
} else {
stream.WriteString(fmt.Sprintf("%v", derr))
}
}
stream.WriteObjectEnd()
}
stream.WriteObjectEnd()
stream.Flush()
return nil
}

// unsubscribe is the callback function for all *_unsubscribe calls.
Expand Down

0 comments on commit 944fd4f

Please sign in to comment.