Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (24 commits)
  account type with zero init nonce (iotexproject#3387)
  [api] Separate Server and Server Handler (iotexproject#3485)
  [ioctl] Build hdwallet derive command line into new ioctl (iotexproject#3418)
  [ioctl] Build hdwallet create command line into new ioctl (iotexproject#3470)
  [makefile] add go mod tidy (iotexproject#3471)
  [api] update chain metrics (iotexproject#3484)
  remove config.EVMNetworkID() (iotexproject#3460)
  [filedao] remove checkMasterChainDBFile() (iotexproject#3463)
  [api] add crashlog (iotexproject#3456)
  [api] Move generateBlockMeta to grpcserver.go (iotexproject#3303)
  [ioctl] Build action hash command line into new ioctl (iotexproject#3425)
  [ioctl] Build hdwallet export command line into new ioctl (iotexproject#3423)
  [ioctl] Refactor nodereward command in new ioctl (iotexproject#3416)
  [ioctl] Cleanup TestNewNodeDelegateCmd (iotexproject#3421)
  [blockchain] Remove BoltDBDaoOption (iotexproject#3465)
  remove InMemDaoOption (iotexproject#3464)
  [action] add evm london test (iotexproject#3402)
  [ioctl] create main for ioctl/newcmd (iotexproject#3296)
  [ioctl] Build block bucket command line into new ioctl (iotexproject#3386)
  [ioctl] Build hdwallet import command line into new ioctl (iotexproject#3419)
  ...
  • Loading branch information
pocockn committed Jul 3, 2022
2 parents 3a272b4 + 7382ab7 commit 3a229d9
Show file tree
Hide file tree
Showing 181 changed files with 7,655 additions and 1,635 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ BUILD_TARGET_SERVER=server
BUILD_TARGET_ACTINJV2=actioninjectorv2
BUILD_TARGET_ADDRGEN=addrgen
BUILD_TARGET_IOCTL=ioctl
BUILD_TARGET_NEWIOCTL=newioctl
BUILD_TARGET_XCTL=xctl
BUILD_TARGET_NEWXCTL=newxctl
BUILD_TARGET_MINICLUSTER=minicluster
BUILD_TARGET_RECOVER=recover
BUILD_TARGET_IOMIGRATER=iomigrater
Expand Down Expand Up @@ -97,6 +99,7 @@ build-staterecoverer:
.PHONY: fmt
fmt:
$(GOCMD) fmt ./...
$(GOCMD) mod tidy

.PHONY: lint
lint:
Expand Down Expand Up @@ -218,6 +221,10 @@ recover:
.PHONY: ioctl
ioctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOCTL) -v ./tools/ioctl

.PHONY: newioctl
newioctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWIOCTL) -v ./tools/newioctl

.PHONY: ioctl-cross
ioctl-cross:
Expand All @@ -229,10 +236,24 @@ ioctl-cross:
cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) .
mkdir -p ./bin/$(BUILD_TARGET_IOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_IOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH)

.PHONY: newioctl-cross
newioctl-cross:
$(DOCKERCMD) pull techknowlogick/xgo:latest
$(GOCMD) get src.techknowlogick.com/xgo
mkdir -p $(GOPATH)/src
sudo cp ./tools/newioctl/ioctl.go $(GOPATH)/src
cd $(GOPATH)/src && sudo rm -f go.mod && $(GOCMD) mod init main && $(GOCMD) mod tidy
cd $(GOPATH)/src && $(GOPATH)/bin/xgo --targets=$(BUILD_TARGET_OS)/$(BUILD_TARGET_ARCH) .
mkdir -p ./bin/$(BUILD_TARGET_NEWIOCTL) && sudo mv $(GOPATH)/src/main-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH) ./bin/$(BUILD_TARGET_NEWIOCTL)/ioctl-$(BUILD_TARGET_OS)-$(BUILD_TARGET_ARCH)

.PHONY: xctl
xctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_XCTL) -v ./tools/xctl

.PHONY: newxctl
newxctl:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_NEWXCTL) -v ./tools/newxctl

.PHONY: iomigrater
iomigrater:
$(GOBUILD) -ldflags "$(PackageFlags)" -o ./bin/$(BUILD_TARGET_IOMIGRATER) -v ./tools/iomigrater
1 change: 1 addition & 0 deletions action/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
ErrChainID = errors.New("invalid chainID")
ErrExistedInPool = errors.New("known transaction")
ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")
ErrSystemActionNonce = errors.New("invalid system action nonce")
ErrNonceTooLow = errors.New("nonce too low")
ErrUnderpriced = errors.New("transaction underpriced")
ErrNegativeValue = errors.New("negative value")
Expand Down
104 changes: 86 additions & 18 deletions action/protocol/account/accountpb/account.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions action/protocol/account/accountpb/account.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018 IoTeX
// Copyright (c) 2022 IoTeX
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
Expand All @@ -8,6 +8,12 @@
// protoc --go_out=plugins=grpc:. *.proto
syntax = "proto3";
package accountpb;
option go_package = "github.com/iotexproject/iotex-core/action/protocol/account/accountpb";

enum AccountType {
DEFAULT = 0;
ZERO_NONCE = 1;
}

message Account {
// used by state-based model
Expand All @@ -17,5 +23,5 @@ message Account {
bytes codeHash = 4;
bool isCandidate = 5;
bytes votingWeight = 6;
AccountType type = 7;
}

21 changes: 15 additions & 6 deletions action/protocol/account/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,25 @@ func (p *Protocol) Name() string {
return protocolID
}

func createAccount(sm protocol.StateManager, encodedAddr string, init *big.Int) error {
var account state.Account
func createAccount(sm protocol.StateManager, encodedAddr string, init *big.Int, opts ...state.AccountCreationOption) error {
account := &state.Account{}
addr, err := address.FromString(encodedAddr)
if err != nil {
return errors.Wrap(err, "failed to get address public key hash from encoded address")
}
addrHash := hash.BytesToHash160(addr.Bytes())
_, err = sm.State(&account, protocol.LegacyKeyOption(addrHash))
_, err = sm.State(account, protocol.LegacyKeyOption(addrHash))
switch errors.Cause(err) {
case nil:
return errors.Errorf("failed to create account %s", encodedAddr)
case state.ErrStateNotExist:
account.Balance = init
account.VotingWeight = big.NewInt(0)
account, err := state.NewAccount(opts...)
if err != nil {
return err
}
if err := account.AddBalance(init); err != nil {
return errors.Wrapf(err, "failed to add balance %s", init)
}
if _, err := sm.PutState(account, protocol.LegacyKeyOption(addrHash)); err != nil {
return errors.Wrapf(err, "failed to put state for account %x", addrHash)
}
Expand All @@ -143,8 +148,12 @@ func (p *Protocol) CreateGenesisStates(ctx context.Context, sm protocol.StateMan
if err := p.assertAmounts(amounts); err != nil {
return err
}
opts := []state.AccountCreationOption{}
if protocol.MustGetFeatureCtx(ctx).CreateLegacyNonceAccount {
opts = append(opts, state.LegacyNonceAccountTypeOption())
}
for i, addr := range addrs {
if err := createAccount(sm, addr.String(), amounts[i]); err != nil {
if err := createAccount(sm, addr.String(), amounts[i], opts...); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions action/protocol/account/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func TestLoadOrCreateAccountState(t *testing.T) {
addrv1 := identityset.Address(27)
s, err := accountutil.LoadAccount(sm, addrv1)
require.NoError(err)
require.Equal(s.Balance, state.EmptyAccount().Balance)
require.Equal(s.Balance, big.NewInt(0))

// create account
require.NoError(createAccount(sm, addrv1.String(), big.NewInt(5)))
require.NoError(createAccount(sm, addrv1.String(), big.NewInt(5), state.LegacyNonceAccountTypeOption()))
s, err = accountutil.LoadAccount(sm, addrv1)
require.NoError(err)
require.Equal("5", s.Balance.String())
require.Equal(uint64(0x0), s.Nonce)
require.Equal(uint64(0x1), s.PendingNonce())
}

func TestProtocol_Initialize(t *testing.T) {
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestProtocol_Initialize(t *testing.T) {
ctx := protocol.WithBlockCtx(context.Background(), protocol.BlockCtx{
BlockHeight: 0,
})
ctx = genesis.WithGenesisContext(ctx, ge)
ctx = protocol.WithFeatureCtx(genesis.WithGenesisContext(ctx, ge))
p := NewProtocol(rewarding.DepositGas)
require.NoError(
p.CreateGenesisStates(
Expand Down
Loading

0 comments on commit 3a229d9

Please sign in to comment.