mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
parent
aa8c43caf3
commit
6a3b92b701
12 changed files with 257 additions and 43 deletions
105
cmd/XDC/bugcmd.go
Normal file
105
cmd/XDC/bugcmd.go
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
// Copyright 2017 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/cmd/internal/browser"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var bugCommand = &cli.Command{
|
||||||
|
Action: reportBug,
|
||||||
|
Name: "bug",
|
||||||
|
Usage: "opens a window to report a bug on the XDC repo",
|
||||||
|
ArgsUsage: " ",
|
||||||
|
}
|
||||||
|
|
||||||
|
const issueUrl = "https://github.com/XinFinOrg/XDPoSChain/issues/new"
|
||||||
|
|
||||||
|
// reportBug reports a bug by opening a new URL to the go-ethereum GH issue
|
||||||
|
// tracker and setting default values as the issue body.
|
||||||
|
func reportBug(ctx *cli.Context) error {
|
||||||
|
// execute template and write contents to buff
|
||||||
|
var buff bytes.Buffer
|
||||||
|
|
||||||
|
fmt.Fprintln(&buff, header)
|
||||||
|
fmt.Fprintln(&buff, "Version:", version.WithMeta)
|
||||||
|
fmt.Fprintln(&buff, "Go Version:", runtime.Version())
|
||||||
|
fmt.Fprintln(&buff, "OS:", runtime.GOOS)
|
||||||
|
printOSDetails(&buff)
|
||||||
|
|
||||||
|
// open a new GH issue
|
||||||
|
if !browser.Open(issueUrl + "?body=" + url.QueryEscape(buff.String())) {
|
||||||
|
fmt.Printf("Please file a new issue at %s using this template:\n%s", issueUrl, buff.String())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// copied from the Go source. Copyright 2017 The Go Authors
|
||||||
|
func printOSDetails(w io.Writer) {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
printCmdOut(w, "uname -v: ", "uname", "-v")
|
||||||
|
printCmdOut(w, "", "sw_vers")
|
||||||
|
case "linux":
|
||||||
|
printCmdOut(w, "uname -sr: ", "uname", "-sr")
|
||||||
|
printCmdOut(w, "", "lsb_release", "-a")
|
||||||
|
case "openbsd", "netbsd", "freebsd", "dragonfly":
|
||||||
|
printCmdOut(w, "uname -v: ", "uname", "-v")
|
||||||
|
case "solaris":
|
||||||
|
out, err := os.ReadFile("/etc/release")
|
||||||
|
if err == nil {
|
||||||
|
fmt.Fprintf(w, "/etc/release: %s\n", out)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("failed to read /etc/release: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// printCmdOut prints the output of running the given command.
|
||||||
|
// It ignores failures; 'go bug' is best effort.
|
||||||
|
//
|
||||||
|
// copied from the Go source. Copyright 2017 The Go Authors
|
||||||
|
func printCmdOut(w io.Writer, prefix, path string, args ...string) {
|
||||||
|
cmd := exec.Command(path, args...)
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s %s: %v\n", path, strings.Join(args, " "), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s%s\n", prefix, bytes.TrimSpace(out))
|
||||||
|
}
|
||||||
|
|
||||||
|
const header = `Please answer these questions before submitting your issue. Thanks!
|
||||||
|
|
||||||
|
#### What did you do?
|
||||||
|
|
||||||
|
#### What did you expect to see?
|
||||||
|
|
||||||
|
#### What did you see instead?
|
||||||
|
|
||||||
|
#### System details`
|
||||||
46
cmd/internal/browser/browser.go
Normal file
46
cmd/internal/browser/browser.go
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package browser provides utilities for interacting with users' browsers.
|
||||||
|
package browser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commands returns a list of possible commands to use to open a url.
|
||||||
|
func Commands() [][]string {
|
||||||
|
var cmds [][]string
|
||||||
|
if exe := os.Getenv("BROWSER"); exe != "" {
|
||||||
|
cmds = append(cmds, []string{exe})
|
||||||
|
}
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
cmds = append(cmds, []string{"/usr/bin/open"})
|
||||||
|
case "windows":
|
||||||
|
cmds = append(cmds, []string{"cmd", "/c", "start"})
|
||||||
|
default:
|
||||||
|
cmds = append(cmds, []string{"xdg-open"})
|
||||||
|
}
|
||||||
|
cmds = append(cmds,
|
||||||
|
[]string{"chrome"},
|
||||||
|
[]string{"google-chrome"},
|
||||||
|
[]string{"chromium"},
|
||||||
|
[]string{"firefox"},
|
||||||
|
)
|
||||||
|
return cmds
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open tries to open url in a browser and reports whether it succeeded.
|
||||||
|
func Open(url string) bool {
|
||||||
|
for _, args := range Commands() {
|
||||||
|
cmd := exec.Command(args[0], append(args[1:], url)...)
|
||||||
|
if cmd.Start() == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
@ -484,8 +484,8 @@ func (st *StateTransition) TransitionDb(owner common.Address) (*ExecutionResult,
|
||||||
|
|
||||||
// validateAuthorization validates an EIP-7702 authorization against the state.
|
// validateAuthorization validates an EIP-7702 authorization against the state.
|
||||||
func (st *StateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
|
func (st *StateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
|
||||||
// Verify chain ID is 0 or equal to current chain ID.
|
// Verify chain ID is null or equal to current chain ID.
|
||||||
if auth.ChainID != 0 && st.evm.ChainConfig().ChainID.Uint64() != auth.ChainID {
|
if !auth.ChainID.IsZero() && auth.ChainID.CmpBig(st.evm.ChainConfig().ChainID) != 0 {
|
||||||
return authority, ErrAuthorizationWrongChainID
|
return authority, ErrAuthorizationWrongChainID
|
||||||
}
|
}
|
||||||
// Limit nonce to 2^64-1 per EIP-2681.
|
// Limit nonce to 2^64-1 per EIP-2681.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ var _ = (*authorizationMarshaling)(nil)
|
||||||
// MarshalJSON marshals as JSON.
|
// MarshalJSON marshals as JSON.
|
||||||
func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) {
|
func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
type SetCodeAuthorization struct {
|
type SetCodeAuthorization struct {
|
||||||
ChainID hexutil.Uint64 `json:"chainId" gencodec:"required"`
|
ChainID hexutil.U256 `json:"chainId" gencodec:"required"`
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
|
Nonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
|
||||||
V hexutil.Uint64 `json:"v" gencodec:"required"`
|
V hexutil.Uint64 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -24,7 +24,7 @@ func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
S hexutil.U256 `json:"s" gencodec:"required"`
|
S hexutil.U256 `json:"s" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var enc SetCodeAuthorization
|
var enc SetCodeAuthorization
|
||||||
enc.ChainID = hexutil.Uint64(s.ChainID)
|
enc.ChainID = hexutil.U256(s.ChainID)
|
||||||
enc.Address = s.Address
|
enc.Address = s.Address
|
||||||
enc.Nonce = hexutil.Uint64(s.Nonce)
|
enc.Nonce = hexutil.Uint64(s.Nonce)
|
||||||
enc.V = hexutil.Uint64(s.V)
|
enc.V = hexutil.Uint64(s.V)
|
||||||
|
|
@ -36,7 +36,7 @@ func (s SetCodeAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
// UnmarshalJSON unmarshals from JSON.
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error {
|
func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error {
|
||||||
type SetCodeAuthorization struct {
|
type SetCodeAuthorization struct {
|
||||||
ChainID *hexutil.Uint64 `json:"chainId" gencodec:"required"`
|
ChainID *hexutil.U256 `json:"chainId" gencodec:"required"`
|
||||||
Address *common.Address `json:"address" gencodec:"required"`
|
Address *common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
|
Nonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
|
||||||
V *hexutil.Uint64 `json:"v" gencodec:"required"`
|
V *hexutil.Uint64 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -50,7 +50,7 @@ func (s *SetCodeAuthorization) UnmarshalJSON(input []byte) error {
|
||||||
if dec.ChainID == nil {
|
if dec.ChainID == nil {
|
||||||
return errors.New("missing required field 'chainId' for SetCodeAuthorization")
|
return errors.New("missing required field 'chainId' for SetCodeAuthorization")
|
||||||
}
|
}
|
||||||
s.ChainID = uint64(*dec.ChainID)
|
s.ChainID = uint256.Int(*dec.ChainID)
|
||||||
if dec.Address == nil {
|
if dec.Address == nil {
|
||||||
return errors.New("missing required field 'address' for SetCodeAuthorization")
|
return errors.New("missing required field 'address' for SetCodeAuthorization")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
enc.YParity = (*hexutil.Uint64)(&yparity)
|
enc.YParity = (*hexutil.Uint64)(&yparity)
|
||||||
|
|
||||||
case *SetCodeTx:
|
case *SetCodeTx:
|
||||||
enc.ChainID = (*hexutil.Big)(new(big.Int).SetUint64(itx.ChainID))
|
enc.ChainID = (*hexutil.Big)(itx.ChainID.ToBig())
|
||||||
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
|
enc.Nonce = (*hexutil.Uint64)(&itx.Nonce)
|
||||||
enc.To = tx.To()
|
enc.To = tx.To()
|
||||||
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
||||||
|
|
@ -323,7 +323,11 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
if dec.ChainID == nil {
|
if dec.ChainID == nil {
|
||||||
return errors.New("missing required field 'chainId' in transaction")
|
return errors.New("missing required field 'chainId' in transaction")
|
||||||
}
|
}
|
||||||
itx.ChainID = dec.ChainID.ToInt().Uint64()
|
var overflow bool
|
||||||
|
itx.ChainID, overflow = uint256.FromBig(dec.ChainID.ToInt())
|
||||||
|
if overflow {
|
||||||
|
return errors.New("'chainId' value overflows uint256")
|
||||||
|
}
|
||||||
if dec.Nonce == nil {
|
if dec.Nonce == nil {
|
||||||
return errors.New("missing required field 'nonce' in transaction")
|
return errors.New("missing required field 'nonce' in transaction")
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +365,6 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
itx.AuthList = dec.AuthorizationList
|
itx.AuthList = dec.AuthorizationList
|
||||||
|
|
||||||
// signature R
|
// signature R
|
||||||
var overflow bool
|
|
||||||
if dec.R == nil {
|
if dec.R == nil {
|
||||||
return errors.New("missing required field 'r' in transaction")
|
return errors.New("missing required field 'r' in transaction")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ func (s pragueSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
|
||||||
}
|
}
|
||||||
// Check that chain ID of tx matches the signer. We also accept ID zero here,
|
// Check that chain ID of tx matches the signer. We also accept ID zero here,
|
||||||
// because it indicates that the chain ID was not specified in the tx.
|
// because it indicates that the chain ID was not specified in the tx.
|
||||||
if txdata.ChainID != 0 && new(big.Int).SetUint64(txdata.ChainID).Cmp(s.chainId) != 0 {
|
if txdata.ChainID != nil && txdata.ChainID.CmpBig(s.chainId) != 0 {
|
||||||
return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId)
|
return nil, nil, nil, fmt.Errorf("%w: have %d want %d", ErrInvalidChainId, txdata.ChainID, s.chainId)
|
||||||
}
|
}
|
||||||
R, S, _ = decodeSignature(sig)
|
R, S, _ = decodeSignature(sig)
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ type DynamicFeeTx struct {
|
||||||
AccessList AccessList
|
AccessList AccessList
|
||||||
|
|
||||||
// Signature values
|
// Signature values
|
||||||
V *big.Int `json:"v" gencodec:"required"`
|
V *big.Int
|
||||||
R *big.Int `json:"r" gencodec:"required"`
|
R *big.Int
|
||||||
S *big.Int `json:"s" gencodec:"required"`
|
S *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy creates a deep copy of the transaction data and initializes all fields.
|
// copy creates a deep copy of the transaction data and initializes all fields.
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func AddressToDelegation(addr common.Address) []byte {
|
||||||
// SetCodeTx implements the EIP-7702 transaction type which temporarily installs
|
// SetCodeTx implements the EIP-7702 transaction type which temporarily installs
|
||||||
// the code at the signer's address.
|
// the code at the signer's address.
|
||||||
type SetCodeTx struct {
|
type SetCodeTx struct {
|
||||||
ChainID uint64
|
ChainID *uint256.Int
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
|
GasTipCap *uint256.Int // a.k.a. maxPriorityFeePerGas
|
||||||
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
|
GasFeeCap *uint256.Int // a.k.a. maxFeePerGas
|
||||||
|
|
@ -61,16 +61,16 @@ type SetCodeTx struct {
|
||||||
AuthList []SetCodeAuthorization
|
AuthList []SetCodeAuthorization
|
||||||
|
|
||||||
// Signature values
|
// Signature values
|
||||||
V *uint256.Int `json:"v" gencodec:"required"`
|
V *uint256.Int
|
||||||
R *uint256.Int `json:"r" gencodec:"required"`
|
R *uint256.Int
|
||||||
S *uint256.Int `json:"s" gencodec:"required"`
|
S *uint256.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run github.com/fjl/gencodec -type SetCodeAuthorization -field-override authorizationMarshaling -out gen_authorization.go
|
//go:generate go run github.com/fjl/gencodec -type SetCodeAuthorization -field-override authorizationMarshaling -out gen_authorization.go
|
||||||
|
|
||||||
// SetCodeAuthorization is an authorization from an account to deploy code at its address.
|
// SetCodeAuthorization is an authorization from an account to deploy code at its address.
|
||||||
type SetCodeAuthorization struct {
|
type SetCodeAuthorization struct {
|
||||||
ChainID uint64 `json:"chainId" gencodec:"required"`
|
ChainID uint256.Int `json:"chainId" gencodec:"required"`
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce uint64 `json:"nonce" gencodec:"required"`
|
Nonce uint64 `json:"nonce" gencodec:"required"`
|
||||||
V uint8 `json:"v" gencodec:"required"`
|
V uint8 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -80,7 +80,7 @@ type SetCodeAuthorization struct {
|
||||||
|
|
||||||
// field type overrides for gencodec
|
// field type overrides for gencodec
|
||||||
type authorizationMarshaling struct {
|
type authorizationMarshaling struct {
|
||||||
ChainID hexutil.Uint64
|
ChainID hexutil.U256
|
||||||
Nonce hexutil.Uint64
|
Nonce hexutil.Uint64
|
||||||
V hexutil.Uint64
|
V hexutil.Uint64
|
||||||
R hexutil.U256
|
R hexutil.U256
|
||||||
|
|
@ -180,7 +180,7 @@ func (tx *SetCodeTx) copy() TxData {
|
||||||
|
|
||||||
// accessors for innerTx.
|
// accessors for innerTx.
|
||||||
func (tx *SetCodeTx) txType() byte { return SetCodeTxType }
|
func (tx *SetCodeTx) txType() byte { return SetCodeTxType }
|
||||||
func (tx *SetCodeTx) chainID() *big.Int { return big.NewInt(int64(tx.ChainID)) }
|
func (tx *SetCodeTx) chainID() *big.Int { return tx.ChainID.ToBig() }
|
||||||
func (tx *SetCodeTx) accessList() AccessList { return tx.AccessList }
|
func (tx *SetCodeTx) accessList() AccessList { return tx.AccessList }
|
||||||
func (tx *SetCodeTx) data() []byte { return tx.Data }
|
func (tx *SetCodeTx) data() []byte { return tx.Data }
|
||||||
func (tx *SetCodeTx) gas() uint64 { return tx.Gas }
|
func (tx *SetCodeTx) gas() uint64 { return tx.Gas }
|
||||||
|
|
@ -207,7 +207,7 @@ func (tx *SetCodeTx) rawSignatureValues() (v, r, s *big.Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *SetCodeTx) setSignatureValues(chainID, v, r, s *big.Int) {
|
func (tx *SetCodeTx) setSignatureValues(chainID, v, r, s *big.Int) {
|
||||||
tx.ChainID = chainID.Uint64()
|
tx.ChainID = uint256.MustFromBig(chainID)
|
||||||
tx.V.SetFromBig(v)
|
tx.V.SetFromBig(v)
|
||||||
tx.R.SetFromBig(r)
|
tx.R.SetFromBig(r)
|
||||||
tx.S.SetFromBig(s)
|
tx.S.SetFromBig(s)
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,7 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction {
|
||||||
}
|
}
|
||||||
data = &types.SetCodeTx{
|
data = &types.SetCodeTx{
|
||||||
To: *args.To,
|
To: *args.To,
|
||||||
ChainID: args.ChainID.ToInt().Uint64(),
|
ChainID: uint256.MustFromBig(args.ChainID.ToInt()),
|
||||||
Nonce: uint64(*args.Nonce),
|
Nonce: uint64(*args.Nonce),
|
||||||
Gas: uint64(*args.Gas),
|
Gas: uint64(*args.Gas),
|
||||||
GasFeeCap: uint256.MustFromBig((*big.Int)(args.MaxFeePerGas)),
|
GasFeeCap: uint256.MustFromBig((*big.Int)(args.MaxFeePerGas)),
|
||||||
|
|
|
||||||
59
p2p/protocols/protocol_test.go
Normal file
59
p2p/protocols/protocol_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Copyright 2017 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package protocols
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/p2p/discover"
|
||||||
|
)
|
||||||
|
|
||||||
|
// handshake message type
|
||||||
|
type hs0 struct {
|
||||||
|
C uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// message to kill/drop the peer with nodeID
|
||||||
|
type kill struct {
|
||||||
|
C discover.NodeID
|
||||||
|
}
|
||||||
|
|
||||||
|
// message to drop connection
|
||||||
|
type drop struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// / protoHandshake represents module-independent aspects of the protocol and is
|
||||||
|
// the first message peers send and receive as part the initial exchange
|
||||||
|
type protoHandshake struct {
|
||||||
|
Version uint // local and remote peer should have identical version
|
||||||
|
NetworkID string // local and remote peer should have identical network id
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkProtoHandshake verifies local and remote protoHandshakes match
|
||||||
|
func checkProtoHandshake(testVersion uint, testNetworkID string) func(interface{}) error {
|
||||||
|
return func(rhs interface{}) error {
|
||||||
|
remote := rhs.(*protoHandshake)
|
||||||
|
if remote.NetworkID != testNetworkID {
|
||||||
|
return fmt.Errorf("%s (!= %s)", remote.NetworkID, testNetworkID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if remote.Version != testVersion {
|
||||||
|
return fmt.Errorf("%d (!= %d)", remote.Version, testVersion)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ var _ = (*stAuthorizationMarshaling)(nil)
|
||||||
// MarshalJSON marshals as JSON.
|
// MarshalJSON marshals as JSON.
|
||||||
func (s stAuthorization) MarshalJSON() ([]byte, error) {
|
func (s stAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
type stAuthorization struct {
|
type stAuthorization struct {
|
||||||
ChainID math.HexOrDecimal64
|
ChainID *math.HexOrDecimal256 `json:"chainId" gencodec:"required"`
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
|
Nonce math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
|
||||||
V math.HexOrDecimal64 `json:"v" gencodec:"required"`
|
V math.HexOrDecimal64 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -24,7 +24,7 @@ func (s stAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
S *math.HexOrDecimal256 `json:"s" gencodec:"required"`
|
S *math.HexOrDecimal256 `json:"s" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var enc stAuthorization
|
var enc stAuthorization
|
||||||
enc.ChainID = math.HexOrDecimal64(s.ChainID)
|
enc.ChainID = (*math.HexOrDecimal256)(s.ChainID)
|
||||||
enc.Address = s.Address
|
enc.Address = s.Address
|
||||||
enc.Nonce = math.HexOrDecimal64(s.Nonce)
|
enc.Nonce = math.HexOrDecimal64(s.Nonce)
|
||||||
enc.V = math.HexOrDecimal64(s.V)
|
enc.V = math.HexOrDecimal64(s.V)
|
||||||
|
|
@ -36,7 +36,7 @@ func (s stAuthorization) MarshalJSON() ([]byte, error) {
|
||||||
// UnmarshalJSON unmarshals from JSON.
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (s *stAuthorization) UnmarshalJSON(input []byte) error {
|
func (s *stAuthorization) UnmarshalJSON(input []byte) error {
|
||||||
type stAuthorization struct {
|
type stAuthorization struct {
|
||||||
ChainID *math.HexOrDecimal64
|
ChainID *math.HexOrDecimal256 `json:"chainId" gencodec:"required"`
|
||||||
Address *common.Address `json:"address" gencodec:"required"`
|
Address *common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
|
Nonce *math.HexOrDecimal64 `json:"nonce" gencodec:"required"`
|
||||||
V *math.HexOrDecimal64 `json:"v" gencodec:"required"`
|
V *math.HexOrDecimal64 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -47,9 +47,10 @@ func (s *stAuthorization) UnmarshalJSON(input []byte) error {
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if dec.ChainID != nil {
|
if dec.ChainID == nil {
|
||||||
s.ChainID = uint64(*dec.ChainID)
|
return errors.New("missing required field 'chainId' for stAuthorization")
|
||||||
}
|
}
|
||||||
|
s.ChainID = (*big.Int)(dec.ChainID)
|
||||||
if dec.Address == nil {
|
if dec.Address == nil {
|
||||||
return errors.New("missing required field 'address' for stAuthorization")
|
return errors.New("missing required field 'address' for stAuthorization")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ type stTransactionMarshaling struct {
|
||||||
|
|
||||||
// Authorization is an authorization from an account to deploy code at its address.
|
// Authorization is an authorization from an account to deploy code at its address.
|
||||||
type stAuthorization struct {
|
type stAuthorization struct {
|
||||||
ChainID uint64
|
ChainID *big.Int `json:"chainId" gencodec:"required"`
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
Nonce uint64 `json:"nonce" gencodec:"required"`
|
Nonce uint64 `json:"nonce" gencodec:"required"`
|
||||||
V uint8 `json:"v" gencodec:"required"`
|
V uint8 `json:"v" gencodec:"required"`
|
||||||
|
|
@ -134,7 +134,7 @@ type stAuthorization struct {
|
||||||
|
|
||||||
// field type overrides for gencodec
|
// field type overrides for gencodec
|
||||||
type stAuthorizationMarshaling struct {
|
type stAuthorizationMarshaling struct {
|
||||||
ChainID math.HexOrDecimal64
|
ChainID *math.HexOrDecimal256
|
||||||
Nonce math.HexOrDecimal64
|
Nonce math.HexOrDecimal64
|
||||||
V math.HexOrDecimal64
|
V math.HexOrDecimal64
|
||||||
R *math.HexOrDecimal256
|
R *math.HexOrDecimal256
|
||||||
|
|
@ -312,7 +312,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
|
||||||
authList = make([]types.SetCodeAuthorization, len(tx.AuthorizationList))
|
authList = make([]types.SetCodeAuthorization, len(tx.AuthorizationList))
|
||||||
for i, auth := range tx.AuthorizationList {
|
for i, auth := range tx.AuthorizationList {
|
||||||
authList[i] = types.SetCodeAuthorization{
|
authList[i] = types.SetCodeAuthorization{
|
||||||
ChainID: auth.ChainID,
|
ChainID: *uint256.MustFromBig(auth.ChainID),
|
||||||
Address: auth.Address,
|
Address: auth.Address,
|
||||||
Nonce: auth.Nonce,
|
Nonce: auth.Nonce,
|
||||||
V: auth.V,
|
V: auth.V,
|
||||||
|
|
@ -323,19 +323,19 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &core.Message{
|
msg := &core.Message{
|
||||||
From: from,
|
From: from,
|
||||||
To: to,
|
To: to,
|
||||||
Nonce: tx.Nonce,
|
Nonce: tx.Nonce,
|
||||||
Value: value,
|
Value: value,
|
||||||
GasLimit: gasLimit,
|
GasLimit: gasLimit,
|
||||||
GasPrice: tx.GasPrice,
|
GasPrice: tx.GasPrice,
|
||||||
GasFeeCap: tx.MaxFeePerGas,
|
GasFeeCap: tx.MaxFeePerGas,
|
||||||
GasTipCap: tx.MaxPriorityFeePerGas,
|
GasTipCap: tx.MaxPriorityFeePerGas,
|
||||||
Data: data,
|
Data: data,
|
||||||
AccessList: accessList,
|
AccessList: accessList,
|
||||||
SetCodeAuthorizations: authList,
|
SetCodeAuthorizations: authList,
|
||||||
SkipNonceChecks: false,
|
SkipNonceChecks: false,
|
||||||
SkipFromEOACheck: false,
|
SkipFromEOACheck: false,
|
||||||
}
|
}
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue