Skip to content

Commit

Permalink
Merge pull request #29 from meshplus/fix/formart_code
Browse files Browse the repository at this point in the history
fix: format code
  • Loading branch information
levi9311 authored Jan 19, 2023
2 parents c174c76 + d530d70 commit e5254e8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 40 deletions.
3 changes: 2 additions & 1 deletion evm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"encoding/binary"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
Expand All @@ -32,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/meshplus/bitxhub-model/constant"
"github.com/meshplus/bitxhub-model/pb"
"math/big"
//lint:ignore SA1019 Needed for precompile
"golang.org/x/crypto/ripemd160"
)
Expand Down
3 changes: 1 addition & 2 deletions evm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
return
}
if common.Bytes2Hex(res) != test.Expected {
bench.Error(fmt.Sprintf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res)))
bench.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res))
return
}
})
Expand Down Expand Up @@ -391,4 +391,3 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) {
}
benchmarkPrecompiled("0f", testcase, b)
}

1 change: 1 addition & 0 deletions evm/runtime/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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/>.

//go:build gofuzz
// +build gofuzz

package runtime
Expand Down
1 change: 0 additions & 1 deletion evm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func setDefaults(cfg *Config) {
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
BerlinBlock: new(big.Int),
YoloV3Block: nil,
}
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/ethereum/go-ethereum v1.10.8
github.com/golang/mock v1.6.0
github.com/holiman/uint256 v1.2.0
github.com/meshplus/bitxhub-kit v1.2.1-0.20210902085548-07f4fa85bfc9
github.com/meshplus/bitxhub-model v1.2.1-0.20221027120259-5b585809c2d6
github.com/meshplus/bitxhub-kit v1.28.0
github.com/meshplus/bitxhub-model v1.28.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.0
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand Down Expand Up @@ -712,8 +714,12 @@ github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104/go.mod h1:XPvLUNfbS4f
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/meshplus/bitxhub-kit v1.2.1-0.20210902085548-07f4fa85bfc9 h1:FFXQrmOz9XMZ/RhYPC8kdMEcsdC1PK/j3W7rleh8ZQ8=
github.com/meshplus/bitxhub-kit v1.2.1-0.20210902085548-07f4fa85bfc9/go.mod h1:wrEdhHp1tktzdwcWb4bOxYsVc+KkcrYL18IYWYeumPQ=
github.com/meshplus/bitxhub-kit v1.28.0 h1:HNYlx6FzELVWqr0GjtWaNo9iMwQTb94bdsqLJo0U2LE=
github.com/meshplus/bitxhub-kit v1.28.0/go.mod h1:S8qKlxfXRFS9HQgXyD4r+o1/0u6EJOQoMZyXtlEM8vM=
github.com/meshplus/bitxhub-model v1.2.1-0.20221027112952-89871ce84dc3 h1:qDpO69RH+VClIpD/JNYVHJXdl0I85l+wVu12u3zIJ6I=
github.com/meshplus/bitxhub-model v1.2.1-0.20221027112952-89871ce84dc3/go.mod h1:BDlfyLxXfOYO6sXw4/2tOgdAUzwJA4epjeXhnXCNvvE=
github.com/meshplus/bitxhub-model v1.28.0 h1:UpZC7IHaZeZHG4IUyKwqOvntx12QmceoyApRIexo5ow=
github.com/meshplus/bitxhub-model v1.28.0/go.mod h1:EehJ/neXJcXy0o1jglfdD1/vsU7tsXveNr9pGZTDtrY=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
Expand Down Expand Up @@ -905,11 +911,14 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4=
Expand Down Expand Up @@ -1088,6 +1097,7 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
Expand Down Expand Up @@ -1466,6 +1476,8 @@ google.golang.org/genproto v0.0.0-20220624142145-8cd45d7dbd1f/go.mod h1:KEWEmljW
google.golang.org/genproto v0.0.0-20220628213854-d9e0b6570c03/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA=
google.golang.org/genproto v0.0.0-20220722212130-b98a9ff5e252/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE=
google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 h1:NX3L5YesD5qgxxrPHdKqHH38Ao0AG6poRXG+JljPsGU=
google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
Expand Down Expand Up @@ -1517,6 +1529,7 @@ google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w=
google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
Expand All @@ -1536,6 +1549,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down
28 changes: 7 additions & 21 deletions ledger/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ func (s *ComplexStateLedger) GetBalance(address *types2.Address) *big.Int {

func (s *ComplexStateLedger) SetBalance(address *types2.Address, b *big.Int) {
stateObject := s.GetOrCreateAccount(address)
if stateObject != nil {
stateObject.SetBalance(b)
}
stateObject.SetBalance(b)
}

func (s *ComplexStateLedger) GetState(address *types2.Address, key []byte) (bool, []byte) {
Expand All @@ -148,23 +146,17 @@ func (s *ComplexStateLedger) GetState(address *types2.Address, key []byte) (bool
// SetState todo(lrx): ComplexStateLedger is not support parallel excutor tx
func (s *ComplexStateLedger) SetState(address *types2.Address, key []byte, value []byte, _ interface{}) {
stateObject := s.GetOrCreateAccount(address)
if stateObject != nil {
stateObject.SetState(key, value, nil)
}
stateObject.SetState(key, value, nil)
}

func (s *ComplexStateLedger) AddState(address *types2.Address, key []byte, value []byte) {
stateObject := s.GetOrCreateAccount(address)
if stateObject != nil {
stateObject.AddState(key, value)
}
stateObject.AddState(key, value)
}

func (s *ComplexStateLedger) SetCode(address *types2.Address, code []byte) {
stateObject := s.GetOrCreateAccount(address)
if stateObject != nil {
stateObject.SetCodeAndHash(code)
}
stateObject.SetCodeAndHash(code)
}

func (s *ComplexStateLedger) GetCode(address *types2.Address) []byte {
Expand All @@ -177,9 +169,7 @@ func (s *ComplexStateLedger) GetCode(address *types2.Address) []byte {

func (s *ComplexStateLedger) SetNonce(address *types2.Address, nonce uint64) {
stateObject := s.GetOrCreateAccount(address)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
stateObject.SetNonce(nonce)
}

func (s *ComplexStateLedger) GetNonce(address *types2.Address) uint64 {
Expand Down Expand Up @@ -451,17 +441,13 @@ func (s *ComplexStateLedger) HasSuicided(addr *types2.Address) bool {
// AddBalance adds amount to the account associated with addr.
func (s *ComplexStateLedger) AddBalance(addr *types2.Address, amount *big.Int) {
stateObject := s.GetOrCreateAccount(addr)
if stateObject != nil {
stateObject.AddBalance(amount)
}
stateObject.AddBalance(amount)
}

// SubBalance subtracts amount from the account associated with addr.
func (s *ComplexStateLedger) SubBalance(addr *types2.Address, amount *big.Int) {
stateObject := s.GetOrCreateAccount(addr)
if stateObject != nil {
stateObject.SubBalance(amount)
}
stateObject.SubBalance(amount)
}

// Suicide marks the given account as suicided.
Expand Down
24 changes: 11 additions & 13 deletions ledger/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
types2 "github.com/meshplus/bitxhub-kit/types"
"github.com/stretchr/testify/assert"
Expand All @@ -47,7 +46,7 @@ func TestUpdateLeaks(t *testing.T) {
state.AddBalance(addr, big.NewInt(int64(11*i)))
state.SetNonce(addr, uint64(42*i))
if i%2 == 0 {
state.SetState(addr, []byte{i, i, i}, []byte{i, i, i, i})
state.SetState(addr, []byte{i, i, i}, []byte{i, i, i, i}, nil)
}
if i%3 == 0 {
state.SetCode(addr, []byte{i, i, i, i, i})
Expand Down Expand Up @@ -80,8 +79,8 @@ func TestIntermediateLeaks(t *testing.T) {
state.SetBalance(addr, big.NewInt(int64(11*i)+int64(tweak)))
state.SetNonce(addr, uint64(42*i+tweak))
if i%2 == 0 {
state.SetState(addr, []byte{i, i, i, 0}, common.Hash{}.Bytes())
state.SetState(addr, []byte{i, i, i, tweak}, common.Hash{i, i, i, i, tweak}.Bytes())
state.SetState(addr, []byte{i, i, i, 0}, common.Hash{}.Bytes(), nil)
state.SetState(addr, []byte{i, i, i, tweak}, common.Hash{i, i, i, i, tweak}.Bytes(), nil)
}
if i%3 == 0 {
state.SetCode(addr, []byte{i, i, i, i, i, tweak})
Expand Down Expand Up @@ -160,7 +159,7 @@ func TestNew(t *testing.T) {
code := []byte{1, 2, 3}
transState.SetCode(addr, code)

transState.SetState(addr, []byte("key"), []byte("value"))
transState.SetState(addr, []byte("key"), []byte("value"), nil)

_, transRoot := transState.FlushDirtyData()
err := transState.Commit(0, nil, transRoot)
Expand All @@ -186,11 +185,11 @@ func TestNew2(t *testing.T) {
transState1, _ := New(&types2.Hash{}, db, nil)

addr := types2.NewAddress([]byte{1})
transState.SetState(addr, []byte("key"), []byte("value"))
transState.SetState(addr, []byte("key"), []byte("value"), nil)
_, transRoot := transState.FlushDirtyData()
_ = transState.Commit(0, nil, transRoot)

transState.SetState(addr, []byte("key1"), []byte("value2"))
transState.SetState(addr, []byte("key1"), []byte("value2"), nil)
_, transRoot2 := transState.FlushDirtyData()
_ = transState.Commit(0, nil, transRoot2)
//err := transState.Database().TrieDB().Commit(common.BytesToHash(root2.Bytes()), false, nil)
Expand All @@ -209,7 +208,7 @@ func TestComplexStateLedger_QueryByPrefix(t *testing.T) {
require.Nil(t, err)
storage, err := rawdb.NewLevelDBDatabase(filepath.Join(root, "ledger"), 0, 0, "", false)
assert.Nil(t, err)
db := state.NewDatabaseWithConfig(storage.(ethdb.Database), &trie.Config{
db := state.NewDatabaseWithConfig(storage, &trie.Config{
Cache: 256,
Journal: "",
Preimages: true,
Expand All @@ -225,13 +224,12 @@ func TestComplexStateLedger_QueryByPrefix(t *testing.T) {

fmt.Println(result)

transState.SetState(addr, []byte("key"), []byte("value"))
transState.SetState(addr, []byte("key1"), []byte("value2"))
transState.SetState(addr, []byte("abc"), []byte("value2"))
transState.SetState(addr, []byte("key"), []byte("value"), nil)
transState.SetState(addr, []byte("key1"), []byte("value2"), nil)
transState.SetState(addr, []byte("abc"), []byte("value2"), nil)
transState.SetNonce(addr, 1)


ok, result := transState.QueryByPrefix(addr, "k")
ok, result = transState.QueryByPrefix(addr, "k")
assert.True(t, ok)
assert.Equal(t, 2, len(result))

Expand Down

0 comments on commit e5254e8

Please sign in to comment.