Skip to content
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

upgrade ethereum to v1.10.23 #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/geth-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ name: GethPublisher
on:
workflow_dispatch:
push:
branches: [ master ]
# branches: [ main, feature/* ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
# pull_request:
# branches: [ main ]

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -14,7 +18,12 @@ env:
jobs:

build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2

Expand All @@ -37,13 +46,16 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=pr
type=semver,pattern=v{{version}}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 15 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package core

import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
Expand All @@ -26,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"math/big"
)

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down Expand Up @@ -56,6 +59,9 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
// returns the amount of gas that was used in the process. If any of the
// transactions failed to execute due to insufficient gas it will return an error.
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
defer func(start time.Time) {
fmt.Printf("Execution state_process, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start))
}(time.Now())
var (
receipts types.Receipts
usedGas = new(uint64)
Expand All @@ -65,7 +71,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
)

vm.BlockDumpLogger(block, 10000, 100)

parityLogContext := vm.ParityLogContext{
Expand Down Expand Up @@ -98,6 +103,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
blockContext := NewEVMBlockContext(header, p.bc, nil)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
// Iterate over and process the individual transactions
var totalts time.Duration = 0.0
for i, tx := range block.Transactions() {
parityLogContext.TxPos = i
parityLogContext.TxHash = tx.Hash()
Expand All @@ -111,12 +117,19 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}

txstart := time.Now()
if err := txLogger.Dump(i, tx, receipt); err != nil {
return nil, nil, 0, fmt.Errorf("could not dump tx %d [%v] logger: %w", i, tx.Hash().Hex(), err)
}

totalts += time.Since(txstart)

receipts = append(receipts, receipt)
allLogs = append(allLogs, receipt.Logs...)
}

fmt.Printf("Dump transaction, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), totalts.Seconds())
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
vm.ReceiptDumpLogger(block.NumberU64(), 10000, 100, receipts)
Expand Down
40 changes: 35 additions & 5 deletions core/vm/dump_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ package vm
import (
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"math/big"
"os"
"path"
"strconv"
"strings"
"time"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -88,6 +89,7 @@ type ParityLogContext struct {

type ParityLogger struct {
context *ParityLogContext
sb *strings.Builder
encoder *json.Encoder
activePrecompiles []common.Address
file *os.File
Expand All @@ -103,19 +105,24 @@ func NewParityLogger(ctx *ParityLogContext, blockNumber uint64, perFolder, perFi
return nil, err
}

l := &ParityLogger{context: ctx, encoder: json.NewEncoder(file), file: file}
sb := &strings.Builder{}
l := &ParityLogger{context: ctx, sb: sb, encoder: json.NewEncoder(sb), file: file}
if l.context == nil {
l.context = &ParityLogContext{}
}
return l, nil
}

func (l *ParityLogger) Close() error {
if _, err := l.file.WriteString(l.sb.String()); err != nil {
return err
}
return l.file.Close()
}

func (l *ParityLogger) CaptureStart(env *EVM, from, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
rules := env.ChainConfig().Rules(env.Context.BlockNumber)
//rules := env.ChainConfig().Rules(env.Context.BlockNumber)
rules := env.ChainConfig().Rules(env.Context.BlockNumber, env.Context.Random != nil)
l.activePrecompiles = ActivePrecompiles(rules)
l.stack = make([]*ParityTraceItem, 0, 20)
l.items = make([]*ParityTraceItem, 0, 20)
Expand All @@ -126,6 +133,12 @@ func (l *ParityLogger) CaptureStart(env *EVM, from, to common.Address, create bo
}
}

func (l *ParityLogger) CaptureTxStart(gasLimit uint64) {
}

func (l *ParityLogger) CaptureTxEnd(restGas uint64) {
}

func (l *ParityLogger) CaptureFault(uint64, OpCode, uint64, uint64, *ScopeContext, int, error) {
}

Expand Down Expand Up @@ -225,12 +238,16 @@ func (l *ParityLogger) CaptureExit(output []byte, gasUsed uint64, err error) {
}

func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts types.Receipts) error {
defer func(start time.Time) {
fmt.Printf("Dump receipt, block_number = %v ,cost time = %v\n", strconv.FormatUint(blockNumber, 10), time.Since(start))
}(time.Now())
file, err := getFile("receipts", blockNumber, perFolder, perFile)
if err != nil {
return err
}

encoder := json.NewEncoder(file)
sb := &strings.Builder{}
encoder := json.NewEncoder(sb)
for _, receipt := range receipts {
for _, log := range receipt.Logs {
err := encoder.Encode(log)
Expand All @@ -239,12 +256,16 @@ func ReceiptDumpLogger(blockNumber uint64, perFolder, perFile uint64, receipts t
}
}
}
if _, err := file.WriteString(sb.String()); err != nil {
return err
}
return nil
}

type TxLogger struct {
blockNumber uint64
blockHash common.Hash
sb *strings.Builder
file *os.File
encoder *json.Encoder
signer types.Signer
Expand All @@ -257,10 +278,12 @@ func NewTxLogger(signer types.Signer, isLondon bool, baseFee *big.Int, blockHash
if err != nil {
return nil, err
}
sb := &strings.Builder{}
return &TxLogger{
blockNumber: blockNumber,
blockHash: blockHash,
file: file,
sb: sb,
encoder: json.NewEncoder(file),
signer: signer,
isLondon: isLondon,
Expand Down Expand Up @@ -294,6 +317,7 @@ func (t *TxLogger) Dump(index int, tx *types.Transaction, receipt *types.Receipt
"effectiveGasPrice": effectiveGasPrice,
"type": tx.Type(),
"value": tx.Value(),
"status": receipt.Status,
}
if err := t.encoder.Encode(entry); err != nil {
return fmt.Errorf("failed to encode transaction entry %w", err)
Expand All @@ -302,10 +326,16 @@ func (t *TxLogger) Dump(index int, tx *types.Transaction, receipt *types.Receipt
}

func (t *TxLogger) Close() error {
if _, err := t.file.WriteString(t.sb.String()); err != nil {
return err
}
return t.file.Close()
}

func BlockDumpLogger(block *types.Block, perFolder, perFile uint64) error {
defer func(start time.Time) {
fmt.Printf("Dump blocks, block_number = %v ,cost time = %v\n", strconv.FormatUint(block.NumberU64(), 10), time.Since(start))
}(time.Now())
file, err := getFile("blocks", block.NumberU64(), perFolder, perFile)
if err != nil {
return err
Expand Down