Skip to content

Commit

Permalink
Merge pull request #86 from testinprod-io/upstream-v2.48.1
Browse files Browse the repository at this point in the history
Upstream sync - v2.48.1
  • Loading branch information
ImTei authored Jul 24, 2023
2 parents 3bd3eeb + 03843d9 commit ebf16c9
Show file tree
Hide file tree
Showing 77 changed files with 828 additions and 1,233 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ clean:
## devtools: installs dev tools (and checks for npm installation etc.)
devtools:
# Notice! If you adding new binary - add it also to cmd/hack/binary-deps/main.go file
$(GOBUILD) -o $(GOBIN)/go-bindata github.com/kevinburke/go-bindata/go-bindata
$(GOBUILD) -o $(GOBIN)/gencodec github.com/fjl/gencodec
$(GOBUILD) -o $(GOBIN)/abigen ./cmd/abigen
$(GOBUILD) -o $(GOBIN)/codecgen github.com/ugorji/go/codec/codecgen
Expand Down
25 changes: 14 additions & 11 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"time"

"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
state2 "github.com/ledgerwatch/erigon-lib/state"
types2 "github.com/ledgerwatch/erigon-lib/types"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/log/v3"

ethereum "github.com/ledgerwatch/erigon"
"github.com/ledgerwatch/erigon/accounts/abi"
Expand All @@ -42,13 +42,15 @@ import (
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/event"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/stages"
)

Expand Down Expand Up @@ -169,11 +171,11 @@ func (b *SimulatedBackend) Rollback() {
}

func (b *SimulatedBackend) emptyPendingBlock() {
chain, _ := core.GenerateChain(b.m.ChainConfig, b.prependBlock, b.m.Engine, b.m.DB, 1, func(int, *core.BlockGen) {}, false /* intermediateHashes */)
b.pendingBlock = chain.Blocks[0]
b.pendingReceipts = chain.Receipts[0]
b.pendingHeader = chain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(params.MaxDataGasPerBlock)
blockChain, _ := core.GenerateChain(b.m.ChainConfig, b.prependBlock, b.m.Engine, b.m.DB, 1, func(int, *core.BlockGen) {})
b.pendingBlock = blockChain.Blocks[0]
b.pendingReceipts = blockChain.Receipts[0]
b.pendingHeader = blockChain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(chain.MaxDataGasPerBlock)
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
Expand Down Expand Up @@ -754,7 +756,8 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
&b.pendingHeader.Coinbase, b.gasPool,
b.pendingState, state.NewNoopWriter(),
b.pendingHeader, tx,
&b.pendingHeader.GasUsed, vm.Config{}); err != nil {
&b.pendingHeader.GasUsed, b.pendingHeader.DataGasUsed,
vm.Config{}); err != nil {
return err
}
//fmt.Printf("==== Start producing block %d\n", (b.prependBlock.NumberU64() + 1))
Expand All @@ -763,7 +766,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}, false /* intermediateHashes */)
})
if err != nil {
return err
}
Expand Down Expand Up @@ -808,7 +811,7 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
block.AddTxWithChain(b.getHeader, b.m.Engine, tx)
}
block.OffsetTime(int64(adjustment.Seconds()))
}, false /* intermediateHashes */)
})
if err != nil {
return err
}
Expand Down Expand Up @@ -841,6 +844,6 @@ func (m callMsg) RollupDataGas() types.RollupGasData { return types.RollupGasDat
func (m callMsg) IsDepositTx() bool { return false }
func (m callMsg) IsSystemTx() bool { return false }

func (m callMsg) DataGas() uint64 { return params.DataGasPerBlob * uint64(len(m.CallMsg.DataHashes)) }
func (m callMsg) DataGas() uint64 { return misc.GetDataGasUsed(len(m.CallMsg.DataHashes)) }
func (m callMsg) MaxFeePerDataGas() *uint256.Int { return m.CallMsg.MaxFeePerDataGas }
func (m callMsg) DataHashes() []libcommon.Hash { return m.CallMsg.DataHashes }
3 changes: 2 additions & 1 deletion cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ func gnosisConfig() BeaconChainConfig {
cfg.BaseRewardFactor = 25
cfg.SlotsPerEpoch = 16
cfg.EpochsPerSyncCommitteePeriod = 512
cfg.CapellaForkEpoch = math.MaxUint64
cfg.CapellaForkEpoch = 648704
cfg.CapellaForkVersion = 0x03000064
cfg.DenebForkEpoch = math.MaxUint64
cfg.InitializeForkSchedule()
return cfg
Expand Down
46 changes: 31 additions & 15 deletions cmd/devnet/devnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Network struct {
Logger log.Logger
BasePrivateApiAddr string
BaseRPCAddr string
Snapshots bool
Nodes []Node
wg sync.WaitGroup
peers []string
Expand Down Expand Up @@ -88,14 +89,23 @@ func (nw *Network) Start(ctx *cli.Context) error {

// get the enode of the node
// - note this has the side effect of waiting for the node to start
if enode, err := getEnode(node); err == nil {
nw.peers = append(nw.peers, enode)
baseNode.StaticPeers = strings.Join(nw.peers, ",")
enode, err := getEnode(node)

// TODO do we need to call AddPeer to the nodes to make them aware of this one
// the current model only works for an appending node network where the peers gossip
// connections - not sure if this is the case ?
if err != nil {
if errors.Is(err, devnetutils.ErrInvalidEnodeString) {
continue
}

nw.Stop()
return err
}

nw.peers = append(nw.peers, enode)
baseNode.StaticPeers = strings.Join(nw.peers, ",")

// TODO do we need to call AddPeer to the nodes to make them aware of this one
// the current model only works for an appending node network where the peers gossip
// connections - not sure if this is the case ?
}
}

Expand Down Expand Up @@ -138,24 +148,27 @@ func (nw *Network) startNode(nodeAddr string, cfg interface{}, nodeNumber int) (
app := erigonapp.MakeApp(fmt.Sprintf("node-%d", nodeNumber), node.run, erigoncli.DefaultFlags)

if err := app.Run(args); err != nil {
_, printErr := fmt.Fprintln(os.Stderr, err)
if printErr != nil {
nw.Logger.Warn("Error writing app run error to stderr", "err", printErr)
}
nw.Logger.Warn("App run returned error", "node", fmt.Sprintf("node-%d", nodeNumber), "err", err)
}
}()

return node, nil
return &node, nil
}

// getEnode returns the enode of the mining node
// getEnode returns the enode of the netowrk node
func getEnode(n Node) (string, error) {
reqCount := 0

for {
nodeInfo, err := n.AdminNodeInfo()

if err != nil {
if r, ok := n.(*node); ok {
if !r.running() {
return "", err
}
}

if reqCount < 10 {
var urlErr *url.Error
if errors.As(err, &urlErr) {
Expand Down Expand Up @@ -193,14 +206,17 @@ func (nw *Network) Run(ctx go_context.Context, scenario scenarios.Scenario) erro
func (nw *Network) Stop() {
type stoppable interface {
Stop()
running() bool
}

for _, n := range nw.Nodes {
if stoppable, ok := n.(stoppable); ok {
stoppable.Stop()
for i, n := range nw.Nodes {
if stoppable, ok := n.(stoppable); ok && stoppable.running() {
nw.Logger.Info("Stopping", "node", i)
go stoppable.Stop()
}
}

nw.Logger.Info("Waiting for nodes to stop")
nw.Wait()
}

Expand Down
13 changes: 13 additions & 0 deletions cmd/devnet/devnet/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
go_context "context"
"sync"

"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/erigon/cmd/devnet/args"
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
"github.com/ledgerwatch/erigon/params"
Expand Down Expand Up @@ -42,6 +43,14 @@ func (n *node) Stop() {
toClose.Close()
}

n.done()
}

func (n *node) running() bool {
return n.ethNode != nil
}

func (n *node) done() {
if n.wg != nil {
wg := n.wg
n.wg = nil
Expand All @@ -59,6 +68,8 @@ func (n *node) run(ctx *cli.Context) error {
var logger log.Logger
var err error

defer n.done()

if logger, err = debug.Setup(ctx, false /* rootLogger */); err != nil {
return err
}
Expand All @@ -68,6 +79,8 @@ func (n *node) run(ctx *cli.Context) error {
nodeCfg := enode.NewNodConfigUrfave(ctx, logger)
ethCfg := enode.NewEthConfigUrfave(ctx, nodeCfg, logger)

nodeCfg.MdbxDBSizeLimit = 512 * datasize.MB

n.ethNode, err = enode.New(nodeCfg, ethCfg, logger)

if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions cmd/devnet/devnetutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package devnetutils
import (
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
"net"
"os"
Expand All @@ -19,29 +20,28 @@ import (
"github.com/ledgerwatch/log/v3"
)

var ErrInvalidEnodeString = errors.New("invalid enode string")

// ClearDevDB cleans up the dev folder used for the operations
func ClearDevDB(dataDir string, logger log.Logger) error {
logger.Info("Deleting nodes' data folders")

nodeNumber := 0
for {
for nodeNumber := 0; nodeNumber < 100; nodeNumber++ { // Arbitrary number
nodeDataDir := filepath.Join(dataDir, fmt.Sprintf("%d", nodeNumber))
fileInfo, err := os.Stat(nodeDataDir)
if err != nil {
if os.IsNotExist(err) {
break
continue
}
return err
}
if fileInfo.IsDir() {
if err := os.RemoveAll(nodeDataDir); err != nil {
return err
}
logger.Info("SUCCESS => Deleted", "datadir", nodeDataDir)
} else {
break
if !fileInfo.IsDir() {
continue
}
if err := os.RemoveAll(nodeDataDir); err != nil {
return err
}
nodeNumber++
logger.Info("SUCCESS => Deleted", "datadir", nodeDataDir)
}
return nil
}
Expand All @@ -56,7 +56,7 @@ func HexToInt(hexStr string) uint64 {
// UniqueIDFromEnode returns the unique ID from a node's enode, removing the `?discport=0` part
func UniqueIDFromEnode(enode string) (string, error) {
if len(enode) == 0 {
return "", fmt.Errorf("invalid enode string")
return "", ErrInvalidEnodeString
}

// iterate through characters in the string until we reach '?'
Expand All @@ -73,14 +73,14 @@ func UniqueIDFromEnode(enode string) (string, error) {
}

if ati == 0 {
return "", fmt.Errorf("invalid enode string")
return "", ErrInvalidEnodeString
}

if _, apiPort, err := net.SplitHostPort(enode[ati+1 : i]); err != nil {
return "", fmt.Errorf("invalid enode string")
return "", ErrInvalidEnodeString
} else {
if _, err := strconv.Atoi(apiPort); err != nil {
return "", fmt.Errorf("invalid enode string")
return "", ErrInvalidEnodeString
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/devnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func action(ctx *cli.Context) error {
network.Stop()

case syscall.SIGINT:
log.Info("Terminating network")
logger.Info("Terminating network")
os.Exit(-int(syscall.SIGINT))
}
}()
Expand Down
2 changes: 1 addition & 1 deletion cmd/devnet/requests/request_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (req *requestGenerator) PingErigonRpc() CallResult {
func NewRequestGenerator(target string, logger log.Logger) RequestGenerator {
return &requestGenerator{
client: &http.Client{
Timeout: time.Second * 600,
Timeout: time.Second * 10,
},
reqID: 1,
logger: logger,
Expand Down
6 changes: 3 additions & 3 deletions cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/node/nodecfg"
"github.com/ledgerwatch/erigon/params"
erigoncli "github.com/ledgerwatch/erigon/turbo/cli"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/services"
Expand Down Expand Up @@ -511,8 +510,9 @@ func (b *blockProcessor) applyBlock(

header := block.Header()
b.vmConfig.Debug = true
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
usedGas := new(uint64)
usedDataGas := new(uint64)
var receipts types.Receipts
rules := b.chainConfig.Rules(block.NumberU64(), block.Time())

Expand Down Expand Up @@ -545,7 +545,7 @@ func (b *blockProcessor) applyBlock(
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
ct := exec3.NewCallTracer()
b.vmConfig.Tracer = ct
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, b.vmConfig)
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, usedDataGas, b.vmConfig)
if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func initialState1() error {
block.AddTx(tx)
}
contractBackend.Commit()
}, true)
})
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/rpcdaemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ The following table shows the current implementation status of Erigon's RPC daem
| bor_getSignersAtHash | Yes | Bor only |
| bor_getCurrentProposer | Yes | Bor only |
| bor_getCurrentValidators | Yes | Bor only |
| bor_getSnapshotProposerSequence | Yes | Bor only |
| bor_getRootHash | Yes | Bor only |

### GraphQL
Expand Down
1 change: 1 addition & 0 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) {
rootCmd.PersistentFlags().StringVar(&cfg.GRPCListenAddress, "grpc.addr", nodecfg.DefaultGRPCHost, "GRPC server listening interface")
rootCmd.PersistentFlags().IntVar(&cfg.GRPCPort, "grpc.port", nodecfg.DefaultGRPCPort, "GRPC server listening port")
rootCmd.PersistentFlags().BoolVar(&cfg.GRPCHealthCheckEnabled, "grpc.healthcheck", false, "Enable GRPC health check")
rootCmd.PersistentFlags().Float64Var(&ethconfig.Defaults.RPCTxFeeCap, utils.RPCGlobalTxFeeCapFlag.Name, utils.RPCGlobalTxFeeCapFlag.Value, utils.RPCGlobalTxFeeCapFlag.Usage)

rootCmd.PersistentFlags().BoolVar(&cfg.TCPServerEnabled, "tcp", false, "Enable TCP server")
rootCmd.PersistentFlags().StringVar(&cfg.TCPListenAddress, "tcp.addr", nodecfg.DefaultTCPHost, "TCP server listening interface")
Expand Down
1 change: 1 addition & 0 deletions cmd/rpcdaemon/commands/bor_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type BorAPI interface {
GetSignersAtHash(hash common.Hash) ([]common.Address, error)
GetCurrentProposer() (common.Address, error)
GetCurrentValidators() ([]*valset.Validator, error)
GetSnapshotProposerSequence(blockNrOrHash *rpc.BlockNumberOrHash) (BlockSigners, error)
GetRootHash(start uint64, end uint64) (string, error)
}

Expand Down
Loading

0 comments on commit ebf16c9

Please sign in to comment.