Merge commit '8f7eb9ccd' into merge/geth-v1.13.11
This commit is contained in:
@@ -76,9 +76,9 @@ func (s *Suite) EthTests() []utesting.Test {
|
||||
{Name: "TestMaliciousHandshake", Fn: s.TestMaliciousHandshake},
|
||||
{Name: "TestMaliciousStatus", Fn: s.TestMaliciousStatus},
|
||||
// test transactions
|
||||
{Name: "TestLargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true},
|
||||
{Name: "TestTransaction", Fn: s.TestTransaction},
|
||||
{Name: "TestInvalidTxs", Fn: s.TestInvalidTxs},
|
||||
{Name: "TestLargeTxRequest", Fn: s.TestLargeTxRequest},
|
||||
{Name: "TestNewPooledTxs", Fn: s.TestNewPooledTxs},
|
||||
{Name: "TestBlobViolations", Fn: s.TestBlobViolations},
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ func TestEthSuite(t *testing.T) {
|
||||
}
|
||||
for _, test := range suite.EthTests() {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
if test.Slow && testing.Short() {
|
||||
t.Skipf("%s: skipping in -short mode", test.Name)
|
||||
}
|
||||
result := utesting.RunTests([]utesting.Test{{Name: test.Name, Fn: test.Fn}}, os.Stdout)
|
||||
if result[0].Failed {
|
||||
t.Fatal()
|
||||
|
||||
@@ -497,7 +497,7 @@ func FindnodeAmplificationWrongIP(t *utesting.T) {
|
||||
// If we receive a NEIGHBORS response, the attack worked and the test fails.
|
||||
reply, _, _ := te.read(te.l2)
|
||||
if reply != nil {
|
||||
t.Error("Got NEIGHORS response for FINDNODE from wrong IP")
|
||||
t.Error("Got NEIGHBORS response for FINDNODE from wrong IP")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/holiman/uint256"
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
@@ -308,15 +309,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
||||
reward.Sub(reward, new(big.Int).SetUint64(ommer.Delta))
|
||||
reward.Mul(reward, blockReward)
|
||||
reward.Div(reward, big.NewInt(8))
|
||||
statedb.AddBalance(ommer.Address, reward)
|
||||
statedb.AddBalance(ommer.Address, uint256.MustFromBig(reward))
|
||||
}
|
||||
statedb.AddBalance(pre.Env.Coinbase, minerReward)
|
||||
statedb.AddBalance(pre.Env.Coinbase, uint256.MustFromBig(minerReward))
|
||||
}
|
||||
// Apply withdrawals
|
||||
for _, w := range pre.Env.Withdrawals {
|
||||
// Amount is in gwei, turn into wei
|
||||
amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei))
|
||||
statedb.AddBalance(w.Address, amount)
|
||||
statedb.AddBalance(w.Address, uint256.MustFromBig(amount))
|
||||
}
|
||||
// Commit block
|
||||
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
|
||||
@@ -359,7 +360,7 @@ func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB
|
||||
for addr, a := range accounts {
|
||||
statedb.SetCode(addr, a.Code)
|
||||
statedb.SetNonce(addr, a.Nonce)
|
||||
statedb.SetBalance(addr, a.Balance)
|
||||
statedb.SetBalance(addr, uint256.MustFromBig(a.Balance))
|
||||
for k, v := range a.Storage {
|
||||
statedb.SetState(addr, k, v)
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ func Transition(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Dump the excution result
|
||||
// Dump the execution result
|
||||
collector := make(Alloc)
|
||||
s.DumpToCollector(collector, nil)
|
||||
return dispatchOutput(ctx, baseDir, result, collector, body)
|
||||
@@ -280,7 +280,7 @@ func (g Alloc) OnAccount(addr *common.Address, dumpAccount state.DumpAccount) {
|
||||
if addr == nil {
|
||||
return
|
||||
}
|
||||
balance, _ := new(big.Int).SetString(dumpAccount.Balance, 10)
|
||||
balance, _ := new(big.Int).SetString(dumpAccount.Balance, 0)
|
||||
var storage map[common.Hash]common.Hash
|
||||
if dumpAccount.Storage != nil {
|
||||
storage = make(map[common.Hash]common.Hash)
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/internal/debug"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -51,9 +50,6 @@ func (c customQuotedStringer) String() string {
|
||||
// logTest is an entry point which spits out some logs. This is used by testing
|
||||
// to verify expected outputs
|
||||
func logTest(ctx *cli.Context) error {
|
||||
// clear field padding map
|
||||
debug.ResetLogging()
|
||||
|
||||
{ // big.Int
|
||||
ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999"
|
||||
bb, _ := new(big.Int).SetString("-111222333444555678999", 10) // "-111,222,333,444,555,678,999"
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// geth is the official command-line client for Ethereum.
|
||||
// geth is a command-line client for Ethereum.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
+54
-9
@@ -25,7 +25,9 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -37,6 +39,7 @@ var (
|
||||
reverseMode = flag.Bool("reverse", false, "convert ASCII to rlp")
|
||||
noASCII = flag.Bool("noascii", false, "don't print ASCII strings readably")
|
||||
single = flag.Bool("single", false, "print only the first element, discard the rest")
|
||||
showpos = flag.Bool("pos", false, "display element byte posititions")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -52,17 +55,17 @@ If the filename is omitted, data is read from stdin.`)
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var r io.Reader
|
||||
var r *inStream
|
||||
switch {
|
||||
case *hexMode != "":
|
||||
data, err := hex.DecodeString(strings.TrimPrefix(*hexMode, "0x"))
|
||||
if err != nil {
|
||||
die(err)
|
||||
}
|
||||
r = bytes.NewReader(data)
|
||||
r = newInStream(bytes.NewReader(data), int64(len(data)))
|
||||
|
||||
case flag.NArg() == 0:
|
||||
r = os.Stdin
|
||||
r = newInStream(bufio.NewReader(os.Stdin), 0)
|
||||
|
||||
case flag.NArg() == 1:
|
||||
fd, err := os.Open(flag.Arg(0))
|
||||
@@ -70,13 +73,19 @@ func main() {
|
||||
die(err)
|
||||
}
|
||||
defer fd.Close()
|
||||
r = fd
|
||||
var size int64
|
||||
finfo, err := fd.Stat()
|
||||
if err == nil {
|
||||
size = finfo.Size()
|
||||
}
|
||||
r = newInStream(bufio.NewReader(fd), size)
|
||||
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr, "Error: too many arguments")
|
||||
flag.Usage()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
out := os.Stdout
|
||||
if *reverseMode {
|
||||
data, err := textToRlp(r)
|
||||
@@ -93,10 +102,10 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func rlpToText(r io.Reader, out io.Writer) error {
|
||||
s := rlp.NewStream(r, 0)
|
||||
func rlpToText(in *inStream, out io.Writer) error {
|
||||
stream := rlp.NewStream(in, 0)
|
||||
for {
|
||||
if err := dump(s, 0, out); err != nil {
|
||||
if err := dump(in, stream, 0, out); err != nil {
|
||||
if err != io.EOF {
|
||||
return err
|
||||
}
|
||||
@@ -110,7 +119,10 @@ func rlpToText(r io.Reader, out io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func dump(s *rlp.Stream, depth int, out io.Writer) error {
|
||||
func dump(in *inStream, s *rlp.Stream, depth int, out io.Writer) error {
|
||||
if *showpos {
|
||||
fmt.Fprintf(out, "%s: ", in.posLabel())
|
||||
}
|
||||
kind, size, err := s.Kind()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -137,7 +149,7 @@ func dump(s *rlp.Stream, depth int, out io.Writer) error {
|
||||
if i > 0 {
|
||||
fmt.Fprint(out, ",\n")
|
||||
}
|
||||
if err := dump(s, depth+1, out); err == rlp.EOL {
|
||||
if err := dump(in, s, depth+1, out); err == rlp.EOL {
|
||||
break
|
||||
} else if err != nil {
|
||||
return err
|
||||
@@ -208,3 +220,36 @@ func textToRlp(r io.Reader) ([]byte, error) {
|
||||
data, err := rlp.EncodeToBytes(obj[0])
|
||||
return data, err
|
||||
}
|
||||
|
||||
type inStream struct {
|
||||
br rlp.ByteReader
|
||||
pos int
|
||||
columns int
|
||||
}
|
||||
|
||||
func newInStream(br rlp.ByteReader, totalSize int64) *inStream {
|
||||
col := int(math.Ceil(math.Log10(float64(totalSize))))
|
||||
return &inStream{br: br, columns: col}
|
||||
}
|
||||
|
||||
func (rc *inStream) Read(b []byte) (n int, err error) {
|
||||
n, err = rc.br.Read(b)
|
||||
rc.pos += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (rc *inStream) ReadByte() (byte, error) {
|
||||
b, err := rc.br.ReadByte()
|
||||
if err == nil {
|
||||
rc.pos++
|
||||
}
|
||||
return b, err
|
||||
}
|
||||
|
||||
func (rc *inStream) posLabel() string {
|
||||
l := strconv.FormatInt(int64(rc.pos), 10)
|
||||
if len(l) < rc.columns {
|
||||
l = strings.Repeat(" ", rc.columns-len(l)) + l
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ func TestRoundtrip(t *testing.T) {
|
||||
"0xc780c0c1c0825208",
|
||||
} {
|
||||
var out strings.Builder
|
||||
err := rlpToText(bytes.NewReader(common.FromHex(want)), &out)
|
||||
in := newInStream(bytes.NewReader(common.FromHex(want)), 0)
|
||||
err := rlpToText(in, &out)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user