Skip to content

Commit

Permalink
抽取Pair等数据结构到公共文件&&新增Simulator Tx RPC&&监听Unknow Router 监控 (bnb-chain#10)
Browse files Browse the repository at this point in the history
* tx

* tx

* Simulator

* RLP

* RPC

* RPC

* RPC

* 新增Unknown Address To Swap事件

* SwapSig

* 抽取Pair等数据结构到公共文件&&新增Simulator Tx RPC&&监听Unknow Router 监控
  • Loading branch information
swlfigo authored Apr 17, 2023
1 parent 7a6c77e commit 3153f72
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cmd/arb
Submodule arb updated from 6706c4 to 69e843
30 changes: 30 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/eth"
"math/big"
"os"
"reflect"
Expand Down Expand Up @@ -325,3 +326,32 @@ func setAccountManagerBackends(stack *node.Node) error {

return nil
}

func makeFullNodeWithEthereum(ctx *cli.Context) (*node.Node, ethapi.Backend, *eth.Ethereum) {
stack, cfg := makeConfigNode(ctx)
if ctx.GlobalIsSet(utils.OverrideBerlinFlag.Name) {
cfg.Eth.OverrideBerlin = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideBerlinFlag.Name))
}
if ctx.GlobalIsSet(utils.OverrideArrowGlacierFlag.Name) {
cfg.Eth.OverrideArrowGlacier = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideArrowGlacierFlag.Name))
}
if ctx.GlobalIsSet(utils.OverrideTerminalTotalDifficulty.Name) {
cfg.Eth.OverrideTerminalTotalDifficulty = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideTerminalTotalDifficulty.Name))
}
backend, ethereumServer := utils.RegisterEthService(stack, &cfg.Eth)

// Configure GraphQL if requested
if ctx.GlobalIsSet(utils.GraphQLEnabledFlag.Name) {
utils.RegisterGraphQLService(stack, backend, cfg.Node)
}
// Add the Ethereum Stats daemon if requested.
if cfg.Ethstats.URL != "" {
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
}

utils.SetupMetrics(ctx,
utils.EnableBuildInfo(gitCommit, gitDate),
utils.EnableMinerInfo(ctx, cfg.Eth.Miner),
)
return stack, backend, ethereumServer
}
10 changes: 8 additions & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
"fmt"
"github.com/ethereum/go-ethereum/cmd/arb/RPCServer"
"os"
"sort"
"strconv"
Expand All @@ -43,6 +44,7 @@ import (
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"

"github.com/ethereum/go-ethereum/cmd/arb/Simulate"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -313,10 +315,14 @@ func geth(ctx *cli.Context) error {
}

prepare(ctx)
stack, backend := makeFullNode(ctx)
//sylarChange
stack, backend, ethereumServer := makeFullNodeWithEthereum(ctx)
defer stack.Close()

//sylarChange
Simulate.GetSimulatorManagerInstance().ConfigEthereumEnv(backend, ethereumServer)
startNode(ctx, stack, backend, false)
//sylarChange
go RPCServer.GetArbRPCServerManagerInstance().StartRPCServer()
stack.Wait()
return nil
}
Expand Down
58 changes: 58 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,61 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
}()
return applyTransaction(msg, config, bc, author, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, receiptProcessors...)
}

// sylarchange
func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, *ExecutionResult, error) {
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), header.BaseFee)
if err != nil {
return nil, nil, err
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
return applyTransactionWithResult(msg, config, bc, author, gp, statedb, header, tx, usedGas, vmenv)
}

// sylarchange
func applyTransactionWithResult(msg types.Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) {
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb)

// Apply the transaction to the current state (included in the env).
result, err := ApplyMessage(evm, msg, gp)
if err != nil {
return nil, nil, err
}

// Update the state with pending changes.
var root []byte
if config.IsByzantium(header.Number) {
statedb.Finalise(true)
} else {
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
}
*usedGas += result.UsedGas

// Create a new receipt for the transaction, storing the intermediate root and gas used
// by the tx.
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: *usedGas}
if result.Failed() {
receipt.Status = types.ReceiptStatusFailed
} else {
receipt.Status = types.ReceiptStatusSuccessful
}
receipt.TxHash = tx.Hash()
receipt.GasUsed = result.UsedGas

// If the transaction created a contract, store the creation address in the receipt.
if msg.To() == nil {
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
}

// Set the receipt logs and create the bloom filter.
receipt.Logs = statedb.GetLogs(tx.Hash(), header.Hash())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
receipt.BlockHash = header.Hash()
receipt.BlockNumber = header.Number
receipt.TransactionIndex = uint(statedb.TxIndex())
return receipt, result, err
}
3 changes: 2 additions & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package eth
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/cmd/arb/Global/MainNodeLocalRedis"
"github.com/go-redis/redis/v8"
"math"
"math/big"
Expand Down Expand Up @@ -793,7 +794,7 @@ func (h *handler) transaction_loop() {
for {
select {
case msg := <-channelTx:
t := &eth.TxCalMsgFromLocalArbRedis{}
t := &MainNodeLocalRedis.TxCalMsgFromLocalArbRedis{}
err := t.UnmarshalBinary([]byte(msg.Payload))
if err != nil {
fmt.Println(err)
Expand Down
12 changes: 10 additions & 2 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package eth

import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/cmd/arb/Global/MainNodeLocalRedis"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -28,6 +30,8 @@ import (
"github.com/ethereum/go-ethereum/trie"
)

var ctx = context.Background()

// handleGetBlockHeaders66 is the eth/66 version of handleGetBlockHeaders
func handleGetBlockHeaders66(backend Backend, msg Decoder, peer *Peer) error {
// Decode the complex header query
Expand Down Expand Up @@ -496,7 +500,9 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
if len(txs) != 0 {
if err := txLocalBrodcastClient.Publish(ctx, "new_txs", GenTxLocalBrodcastMsg(txs)).Err(); err != nil { //主节点广播新收到的TX发送到本地Redis处理,arb处理完回传Geth
if err := MainNodeLocalRedis.MainNodeLocalRedisClient.Publish(ctx, "new_txs", &MainNodeLocalRedis.TxLocalBrodcastMsgInfo{
TX: txs,
}).Err(); err != nil { //主节点广播新收到的TX发送到本地Redis处理,arb处理完回传Geth
panic(err)
}
}
Expand All @@ -521,7 +527,9 @@ func handlePooledTransactions66(backend Backend, msg Decoder, peer *Peer) error
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
}
if len(txs.PooledTransactionsPacket) != 0 {
if err := txLocalBrodcastClient.Publish(ctx, "new_txs", GenTxLocalBrodcastMsg(txs.PooledTransactionsPacket)).Err(); err != nil { //主节点广播新收到的TX发送到本地Redis处理,arb处理完回传Geth
if err := MainNodeLocalRedis.MainNodeLocalRedisClient.Publish(ctx, "new_txs", &MainNodeLocalRedis.TxLocalBrodcastMsgInfo{
TX: txs.PooledTransactionsPacket,
}).Err(); err != nil { //主节点广播新收到的TX发送到本地Redis处理,arb处理完回传Geth
panic(err)
}
}
Expand Down
52 changes: 0 additions & 52 deletions eth/protocols/eth/tx_redis_brodcast_handler.go

This file was deleted.

0 comments on commit 3153f72

Please sign in to comment.