Skip to content

Commit

Permalink
Merge pull request #1592 from klaytn/release/v1.9.1
Browse files Browse the repository at this point in the history
[Master] release/v1.9.1 QA Sign-off
  • Loading branch information
aidan-kwon committed Aug 19, 2022
2 parents 51c0105 + 7c34497 commit 8664bc8
Show file tree
Hide file tree
Showing 55 changed files with 3,178 additions and 1,933 deletions.
9 changes: 8 additions & 1 deletion api/api_ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,14 @@ func EthDoCall(ctx context.Context, b Backend, args EthTransactionArgs, blockNrO
if err != nil {
return nil, 0, 0, err
}
st.AddBalance(msg.ValidatedSender(), new(big.Int).Mul(new(big.Int).SetUint64(msg.Gas()), msg.GasPrice()))
var balanceBaseFee *big.Int
if header.BaseFee != nil {
balanceBaseFee = new(big.Int).Mul(baseFee, common.Big2)
} else {
balanceBaseFee = msg.GasPrice()
}
// Add gas fee to sender for estimating gasLimit/computing cost or calling a function by insufficient balance sender.
st.AddBalance(msg.ValidatedSender(), new(big.Int).Mul(new(big.Int).SetUint64(msg.Gas()), balanceBaseFee))

// The intrinsicGas is checked again later in the blockchain.ApplyMessage function,
// but we check in advance here in order to keep StateTransition.TransactionDb method as unchanged as possible
Expand Down
9 changes: 7 additions & 2 deletions api/api_public_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,14 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if err != nil {
return nil, 0, 0, 0, err
}

var balanceBaseFee *big.Int
if header.BaseFee != nil {
balanceBaseFee = new(big.Int).Mul(baseFee, common.Big2)
} else {
balanceBaseFee = msg.GasPrice()
}
// Add gas fee to sender for estimating gasLimit/computing cost or calling a function by insufficient balance sender.
state.AddBalance(msg.ValidatedSender(), new(big.Int).Mul(new(big.Int).SetUint64(msg.Gas()), msg.GasPrice()))
state.AddBalance(msg.ValidatedSender(), new(big.Int).Mul(new(big.Int).SetUint64(msg.Gas()), balanceBaseFee))

// The intrinsicGas is checked again later in the blockchain.ApplyMessage function,
// but we check in advance here in order to keep StateTransition.TransactionDb method as unchanged as possible
Expand Down
89 changes: 55 additions & 34 deletions api/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,73 +32,94 @@ import (
"github.com/klaytn/klaytn/log/term"
colorable "github.com/mattn/go-colorable"
"gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1/altsrc"
)

var Memsize memsizeui.Handler

var (
verbosityFlag = cli.IntFlag{
Name: "verbosity",
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
Value: 3,
Name: "verbosity",
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
Value: 3,
EnvVar: "KLAYTN_VERBOSITY",
}
vmoduleFlag = cli.StringFlag{
Name: "vmodule",
Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. klay/*=5,p2p=4)",
Value: "",
Name: "vmodule",
Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. klay/*=5,p2p=4)",
Value: "",
EnvVar: "KLAYTN_VMODULE",
}
backtraceAtFlag = cli.StringFlag{
Name: "backtrace",
Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")",
Value: "",
Name: "backtrace",
Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")",
Value: "",
EnvVar: "KLAYTN_BACKTRACE",
}
debugFlag = cli.BoolFlag{
Name: "debug",
Usage: "Prepends log messages with call-site location (file and line number)",
Name: "debug",
Usage: "Prepends log messages with call-site location (file and line number)",
EnvVar: "KLAYTN_DEBUG",
}
pprofFlag = cli.BoolFlag{
Name: "pprof",
Usage: "Enable the pprof HTTP server",
Name: "pprof",
Usage: "Enable the pprof HTTP server",
EnvVar: "KLAYTN_PPROF",
}
pprofPortFlag = cli.IntFlag{
Name: "pprofport",
Usage: "pprof HTTP server listening port",
Value: 6060,
Name: "pprofport",
Usage: "pprof HTTP server listening port",
Value: 6060,
EnvVar: "KLAYTN_PPROFPORT",
}
pprofAddrFlag = cli.StringFlag{
Name: "pprofaddr",
Usage: "pprof HTTP server listening interface",
Value: "127.0.0.1",
Name: "pprofaddr",
Usage: "pprof HTTP server listening interface",
Value: "127.0.0.1",
EnvVar: "KLAYTN_PPROFADDR",
}
memprofileFlag = cli.StringFlag{
Name: "memprofile",
Usage: "Write memory profile to the given file",
Name: "memprofile",
Usage: "Write memory profile to the given file",
EnvVar: "KLAYTN_MEMPROFILE",
}
memprofilerateFlag = cli.IntFlag{
Name: "memprofilerate",
Usage: "Turn on memory profiling with the given rate",
Value: runtime.MemProfileRate,
Name: "memprofilerate",
Usage: "Turn on memory profiling with the given rate",
Value: runtime.MemProfileRate,
EnvVar: "KLAYTN_MEMPROFILERATE",
}
blockprofilerateFlag = cli.IntFlag{
Name: "blockprofilerate",
Usage: "Turn on block profiling with the given rate",
Name: "blockprofilerate",
Usage: "Turn on block profiling with the given rate",
EnvVar: "KLAYTN_BLOCKPROFILERATE",
}
cpuprofileFlag = cli.StringFlag{
Name: "cpuprofile",
Usage: "Write CPU profile to the given file",
Name: "cpuprofile",
Usage: "Write CPU profile to the given file",
EnvVar: "KLAYTN_CPUPROFILE",
}
traceFlag = cli.StringFlag{
Name: "trace",
Usage: "Write execution trace to the given file",
Name: "trace",
Usage: "Write execution trace to the given file",
EnvVar: "KLAYTN_TRACE",
}
)

// Flags holds all command-line flags required for debugging.
var Flags = []cli.Flag{
verbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag,
pprofFlag, pprofAddrFlag, pprofPortFlag,
memprofileFlag, memprofilerateFlag,
blockprofilerateFlag, cpuprofileFlag, traceFlag,
altsrc.NewIntFlag(verbosityFlag),
altsrc.NewStringFlag(vmoduleFlag),
altsrc.NewStringFlag(backtraceAtFlag),
altsrc.NewBoolFlag(debugFlag),
altsrc.NewBoolFlag(pprofFlag),
altsrc.NewStringFlag(pprofAddrFlag),
altsrc.NewIntFlag(pprofPortFlag),
altsrc.NewStringFlag(memprofileFlag),
altsrc.NewIntFlag(memprofilerateFlag),
altsrc.NewIntFlag(blockprofilerateFlag),
altsrc.NewStringFlag(cpuprofileFlag),
altsrc.NewStringFlag(traceFlag),
}

var glogger *log.GlogHandler
Expand Down
5 changes: 4 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var (
snapshotStorageReadTimer = metrics.NewRegisteredTimer("state/snapshot/storage/reads", nil)
snapshotCommitTimer = metrics.NewRegisteredTimer("state/snapshot/commits", nil)

blockBaseFee = metrics.NewRegisteredGauge("chain/basefee", nil)
blockInsertTimer = klaytnmetrics.NewRegisteredHybridTimer("chain/inserts", nil)
blockProcessTimer = klaytnmetrics.NewRegisteredHybridTimer("chain/process", nil)
blockExecutionTimer = klaytnmetrics.NewRegisteredHybridTimer("chain/execution", nil)
Expand Down Expand Up @@ -2023,6 +2024,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
"processTxs", processTxsTime, "finalize", processFinalizeTime, "validateState", validateTime,
"totalWrite", writeResult.TotalWriteTime, "trieWrite", writeResult.TrieWriteTime)

if block.Header().BaseFee != nil {
blockBaseFee.Update(block.Header().BaseFee.Int64() / int64(params.Ston))
}
blockProcessTimer.Update(time.Duration(processTxsTime))
blockExecutionTimer.Update(time.Duration(processTxsTime) - trieAccess)
blockFinalizeTimer.Update(time.Duration(processFinalizeTime))
Expand Down Expand Up @@ -2630,7 +2634,6 @@ func (bc *BlockChain) ApplyTransaction(chainConfig *params.ChainConfig, author *
internalTrace, err = GetInternalTxTrace(vmConfig.Tracer)
if err != nil {
logger.Error("failed to get tracing result from a transaction", "txHash", tx.Hash().String(), "err", err)
return nil, 0, nil, err
}
}
// Update the state with pending changes
Expand Down
10 changes: 10 additions & 0 deletions blockchain/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package blockchain

import (
"encoding/json"

"github.com/klaytn/klaytn/blockchain/types"
"github.com/klaytn/klaytn/blockchain/vm"
"github.com/klaytn/klaytn/common"
Expand Down Expand Up @@ -51,6 +53,14 @@ type ChainEvent struct {
InternalTxTraces []*vm.InternalTxTrace
}

func (ev *ChainEvent) JsonSize() common.StorageSize {
jsonBytes, err := json.Marshal(ev)
if err != nil {
return common.StorageSize(0)
}
return common.StorageSize(len(jsonBytes))
}

type ChainSideEvent struct {
Block *types.Block
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/vm/internaltx_trace_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestInternalTxTracer_result_invalidOutput(t *testing.T) {
// An 8 bytes value that might cause a string version error or out-of-range error.
tracer.ctx["output"] = "0x08c379a0000000000000000000000000000000000000000000000000ffffffffffffffff000000000000000000000000000000000000000000000000ffffffffffffffff"

_, err := tracer.result()
_, err := tracer.GetResult()
if err != nil {
t.Fatal(err)
}
Expand Down
73 changes: 9 additions & 64 deletions blockchain/vm/internaltx_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
package vm

import (
"encoding/hex"
"errors"
"fmt"
"math/big"
"strconv"
"sync/atomic"
"time"

"github.com/klaytn/klaytn/accounts/abi"
"github.com/klaytn/klaytn/common"
"github.com/klaytn/klaytn/common/hexutil"
)
Expand Down Expand Up @@ -425,10 +424,7 @@ func (this *InternalTxTracer) CaptureEnd(output []byte, gasUsed uint64, t time.D
}

func (this *InternalTxTracer) GetResult() (*InternalTxTrace, error) {
result, err := this.result()
if err != nil {
this.err = wrapError("result", err)
}
result := this.result()
// Clean up the JavaScript environment
this.reset()
return result, this.err
Expand All @@ -448,7 +444,7 @@ func (this *InternalTxTracer) reset() {

// result is invoked when all the opcodes have been iterated over and returns
// the final result of the tracing.
func (this *InternalTxTracer) result() (*InternalTxTrace, error) {
func (this *InternalTxTracer) result() *InternalTxTrace {
if _, exist := this.ctx["type"]; !exist {
this.ctx["type"] = ""
}
Expand Down Expand Up @@ -515,69 +511,18 @@ func (this *InternalTxTracer) result() (*InternalTxTrace, error) {
}
if err := this.ctx["error"]; err != nil && err.(error).Error() == errEvmExecutionReverted.Error() {
outputHex := this.ctx["output"].(string) // it is already a hex string
outputHexLength := len(outputHex)

// outputHexLength should be equal for larger than 138 (10+32*2+32*2) to parse a revert string
// outputHex[:10]: "0x08c379a0" == crypto.Keccak256([]byte("Error(string)"))[:4]
// outputHex[10:10+32*2]: a revert string
// outputHex[10+32*2:10+32*2+32*2]: the length of a revert string
if outputHexLength >= 138 && outputHex[2:10] == "08c379a0" {
defaultOffset := 10

// TODO-Klaytn: introduce error handling logic for the case the parsing data is bigger than math.MaxUint64
stringOffset, err := strconv.ParseUint(outputHex[defaultOffset+32*2-8:defaultOffset+32*2], 16, 64)
if err != nil {
logger.Error("failed to parse hex string to get stringOffset",
"err", err, "outputHex", outputHex)
return nil, err
}
stringLength, err := strconv.ParseUint(outputHex[defaultOffset+32*2+32*2-8:defaultOffset+32*2+32*2], 16, 64)
if err != nil {
logger.Error("failed to parse hex string to get stringLength",
"err", err, "outputHex", outputHex)
return nil, err
}

if stringOffset > uint64(outputHexLength) {
stringOffset = 0
}
if stringLength > uint64(outputHexLength) {
stringLength = 0
}

start := defaultOffset + 32*2 + int(stringOffset*2)
end := start + int(stringLength*2)

if start < 0 {
start = 0
}
if end < 0 {
end = 0
}
// return nothing if end is out of the range
if end > outputHexLength {
start = outputHexLength - 1
end = outputHexLength - 1
}

// left-padding with 0 for hex decoding
outputHexSlice := outputHex[start:end]
if len(outputHexSlice)%2 == 1 {
outputHexSlice = "0" + outputHexSlice
}
asciiInBytes, err := hex.DecodeString(outputHexSlice)
if err != nil {
logger.Error("failed to parse hex string to get ASCII representation",
"err", err, "outputHex", outputHex)
return nil, err
}
this.revertString = string(asciiInBytes)
if s, err := abi.UnpackRevert(common.FromHex(outputHex)); err == nil {
this.revertString = s
} else {
this.revertString = ""
}

contract := this.revertedContract
message := this.revertString
result.Reverted = &RevertedInfo{Contract: &contract, Message: message}
}
return result, nil
return result
}

// InternalTxLogs returns the captured tracerLog entries.
Expand Down
2 changes: 1 addition & 1 deletion build/update-license.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ var (
"node/cn/handler.go": "eth/handler.go",
"node/cn/api_backend.go": "eth/api_backend.go",
"node/cn/api_sc_backend.go": "eth/api_backend.go",
"node/cn/api_tracer.go": "eth/api_tracer.go",
"node/cn/tracers/api.go": "eth/tracers/api.go",
"node/cn/config.go": "eth/config.go",
"node/cn/backend.go": "eth/backend.go",
"node/cn/sc_backend.go": "eth/backend.go",
Expand Down
11 changes: 1 addition & 10 deletions cmd/homi/setup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,16 +677,7 @@ func writePNInfoKey(num int) {
}

func writeKlayConfig(networkId int, rpcPort int, wsPort int, p2pPort int, dataDir string, logDir string, nodeType string) {
kConfig := KlaytnConfig{
networkId,
rpcPort,
wsPort,
p2pPort,
dataDir,
logDir,
"/var/run/klay",
nodeType,
}
kConfig := NewKlaytnConfig(networkId, rpcPort, wsPort, p2pPort, dataDir, logDir, "/var/run/klay", nodeType)
WriteFile([]byte(kConfig.String()), strings.ToLower(nodeType), "klay.conf")
}

Expand Down
17 changes: 9 additions & 8 deletions cmd/homi/setup/klaytn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ type KlaytnConfig struct {
NodeType string
}

func New(rpcPort int, wsPort int, p2pPort int, dataDir string, logDir string, runDir string, nodeType string) *KlaytnConfig {
func NewKlaytnConfig(networkId int, rpcPort int, wsPort int, p2pPort int, dataDir string, logDir string, runDir string, nodeType string) *KlaytnConfig {
kConf := &KlaytnConfig{
RPCPort: rpcPort,
WSPort: wsPort,
P2PPort: p2pPort,
DataDir: dataDir,
LogDir: logDir,
RunDir: runDir,
NodeType: nodeType,
NetworkId: networkId,
RPCPort: rpcPort,
WSPort: wsPort,
P2PPort: p2pPort,
DataDir: dataDir,
LogDir: logDir,
RunDir: runDir,
NodeType: nodeType,
}
return kConf
}
Expand Down
Loading

0 comments on commit 8664bc8

Please sign in to comment.