Skip to content

Commit

Permalink
Merge branch 'master' into ioctl_insecure_newcmd
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie authored Feb 6, 2023
2 parents 39ad022 + 6fe6a17 commit 36937bd
Show file tree
Hide file tree
Showing 87 changed files with 4,902 additions and 373 deletions.
23 changes: 11 additions & 12 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@

#Specific owners
/consensus/ @CoderZhi
/ioctl/ @huof6829
/api/ @Liuhaai @millken
/ioctl/ @huof6829 @CoderZhi
/api/ @Liuhaai @millken @CoderZhi
/config/ @dustinxie @CoderZhi
/p2p/ @Liuhaai @dustinxie

/action/ @dustinxie
/blockchain/ @dustinxie
/blockindex/ @dustinxie
/crypto/ @dustinxie
/db/ @dustinxie
/dispatcher/ @dustinxie
/action/ @CoderZhi @dustinxie
/blockchain/ @CoderZhi @dustinxie
/blockindex/ @CoderZhi @dustinxie
/crypto/ @CoderZhi @dustinxie
/db/ @CoderZhi @dustinxie @Liuhaai
/dispatcher/ @CoderZhi @dustinxie
/pkg/ @dustinxie
/server/ @dustinxie
/state/ @dustinxie
/actpool/ @Liuhaai
/server/ @CoderZhi @dustinxie
/state/ @CoderZhi @dustinxie
/actpool/ @CoderZhi @Liuhaai
/.github/workflows @dustinxie @xianhuawei
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ jobs:
with:
go-version: 1.18.5
cache: false


- name: Build Go
run: go build ./...

# - name: Error Check
# uses: reviewdog/action-golangci-lint@v2
# with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If the dependency needs to be updated, run
go get -u
go mod tidy
```
If you want learn more advanced usage about `go mod`, you can find out [here](https://github.com/golang/go/wiki/Modules).
If you want to learn more advanced usage about `go mod`, you can find out [here](https://github.com/golang/go/wiki/Modules).

Run unit tests only by

Expand All @@ -83,7 +83,7 @@ make docker

### Run iotex-core

Start (or resume) a standalone server to operate on an blockchain by
Start (or resume) a standalone server to operate on a blockchain by

```
make run
Expand Down
121 changes: 121 additions & 0 deletions action/action_deserializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
package action

import (
"encoding/binary"
"encoding/hex"
"fmt"
"math/big"
"testing"

"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-proto/golang/iotextypes"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/testutil"
)

func TestActionDeserializer(t *testing.T) {
Expand Down Expand Up @@ -68,3 +74,118 @@ func TestProtoWithChainID(t *testing.T) {
r.Equal(v.err, selp.VerifySignature())
}
}

func TestDataContanetation(t *testing.T) {
require := require.New(t)

// raw data
tx1, _ := SignedTransfer(identityset.Address(28).String(),
identityset.PrivateKey(28), 3, big.NewInt(10), []byte{}, testutil.TestGasLimit,
big.NewInt(testutil.TestGasPriceInt64))
txHash1, _ := tx1.Hash()
serilizedTx1, err := proto.Marshal(tx1.Proto())
require.NoError(err)
tx2, _ := SignedExecution(identityset.Address(29).String(),
identityset.PrivateKey(29), 1, big.NewInt(0), testutil.TestGasLimit,
big.NewInt(testutil.TestGasPriceInt64), []byte{})
txHash2, _ := tx2.Hash()
serilizedTx2, err := proto.Marshal(tx2.Proto())
require.NoError(err)

t.Run("tx1", func(t *testing.T) {
act1 := &iotextypes.Action{}
err := proto.Unmarshal(serilizedTx1, act1)
require.NoError(err)
se1, err := (&Deserializer{}).ActionToSealedEnvelope(act1)
require.NoError(err)
actHash1, err := se1.Hash()
require.NoError(err)
require.Equal(txHash1, actHash1)

act2 := &iotextypes.Action{}
err = proto.Unmarshal(serilizedTx2, act2)
require.NoError(err)
})

t.Run("tx2", func(t *testing.T) {
act2 := &iotextypes.Action{}
err = proto.Unmarshal(serilizedTx2, act2)
require.NoError(err)
se2, err := (&Deserializer{}).ActionToSealedEnvelope(act2)
require.NoError(err)
actHash2, err := se2.Hash()
require.NoError(err)
require.Equal(txHash2, actHash2)
})

t.Run("tx1+tx2", func(t *testing.T) {
acts := &iotextypes.Actions{}
err = proto.Unmarshal(append(serilizedTx1, serilizedTx2...), acts)
require.NoError(err)
require.Equal(2, len(acts.Actions))
_, err := (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[0])
require.Error(err)
})

rawActs1 := &iotextypes.Actions{
Actions: []*iotextypes.Action{tx1.Proto()},
}
serilizedActs1, err := proto.Marshal(rawActs1)
require.NoError(err)
rawActs2 := &iotextypes.Actions{
Actions: []*iotextypes.Action{tx2.Proto()},
}
serilizedActs2, err := proto.Marshal(rawActs2)
require.NoError(err)

t.Run("tx1", func(t *testing.T) {
acts := &iotextypes.Actions{}
err = proto.Unmarshal(serilizedActs1, acts)
require.NoError(err)
require.Equal(1, len(acts.Actions))
se, err := (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[0])
require.NoError(err)
actHash, err := se.Hash()
require.NoError(err)
require.Equal(txHash1, actHash)
})

t.Run("tx2", func(t *testing.T) {
acts := &iotextypes.Actions{}
err = proto.Unmarshal(serilizedActs2, acts)
require.NoError(err)
require.Equal(1, len(acts.Actions))
se, err := (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[0])
require.NoError(err)
actHash, err := se.Hash()
require.NoError(err)
require.Equal(txHash2, actHash)
})

t.Run("tx1+tx2+tx1", func(t *testing.T) {
acts := &iotextypes.Actions{}
data := append(serilizedActs1, serilizedActs2...)
data = append(data, serilizedActs1...)
fmt.Println(binary.Size(data))
err = proto.Unmarshal(data, acts)
require.NoError(err)
require.Equal(3, len(acts.Actions))
se, err := (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[0])
require.NoError(err)
actHash, err := se.Hash()
require.NoError(err)
require.Equal(txHash1, actHash)

se, err = (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[1])
require.NoError(err)
actHash, err = se.Hash()
require.NoError(err)
require.Equal(txHash2, actHash)

se, err = (&Deserializer{}).ActionToSealedEnvelope(acts.Actions[2])
require.NoError(err)
actHash, err = se.Hash()
require.NoError(err)
require.Equal(txHash1, actHash)
})
}
12 changes: 2 additions & 10 deletions action/protocol/account/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import (
const TransferSizeLimit = 32 * 1024

// handleTransfer handles a transfer
func (p *Protocol) handleTransfer(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error) {
tsf, ok := act.(*action.Transfer)
if !ok {
return nil, nil
}
func (p *Protocol) handleTransfer(ctx context.Context, tsf *action.Transfer, sm protocol.StateManager) (*action.Receipt, error) {
var (
fCtx = protocol.MustGetFeatureCtx(ctx)
actionCtx = protocol.MustGetActionCtx(ctx)
Expand Down Expand Up @@ -162,11 +158,7 @@ func (p *Protocol) handleTransfer(ctx context.Context, act action.Action, sm pro
}

// validateTransfer validates a transfer
func (p *Protocol) validateTransfer(ctx context.Context, act action.Action) error {
tsf, ok := act.(*action.Transfer)
if !ok {
return nil
}
func (p *Protocol) validateTransfer(ctx context.Context, tsf *action.Transfer) error {
// Reject oversized transfer
if tsf.TotalSize() > TransferSizeLimit {
return action.ErrOversizedData
Expand Down
2 changes: 2 additions & 0 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type (
FixUnproductiveDelegates bool
CorrectGasRefund bool
FixRewardErroCheckPosition bool
EnableWeb3Rewarding bool
}

// FeatureWithHeightCtx provides feature check functions.
Expand Down Expand Up @@ -244,6 +245,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
FixUnproductiveDelegates: g.IsOkhotsk(height),
CorrectGasRefund: g.IsOkhotsk(height),
FixRewardErroCheckPosition: g.IsOkhotsk(height),
EnableWeb3Rewarding: g.IsToBeEnabled(height),
},
)
}
Expand Down
31 changes: 11 additions & 20 deletions actpool/actpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,19 @@ func (p SortedActions) Less(i, j int) bool { return p[i].Nonce() < p[j].Nonce()
// Option sets action pool construction parameter
type Option func(pool *actPool) error

// EnableExperimentalActions enables the action pool to take experimental actions
func EnableExperimentalActions() Option {
return func(pool *actPool) error {
pool.enableExperimentalActions = true
return nil
}
}

// actPool implements ActPool interface
type actPool struct {
cfg Config
g genesis.Genesis
sf protocol.StateReader
accountDesActs *destinationMap
allActions *ttl.Cache
gasInPool uint64
actionEnvelopeValidators []action.SealedEnvelopeValidator
timerFactory *prometheustimer.TimerFactory
enableExperimentalActions bool
senderBlackList map[string]bool
jobQueue []chan workerJob
worker []*queueWorker
cfg Config
g genesis.Genesis
sf protocol.StateReader
accountDesActs *destinationMap
allActions *ttl.Cache
gasInPool uint64
actionEnvelopeValidators []action.SealedEnvelopeValidator
timerFactory *prometheustimer.TimerFactory
senderBlackList map[string]bool
jobQueue []chan workerJob
worker []*queueWorker
}

// NewActPool constructs a new actpool
Expand Down
Loading

0 comments on commit 36937bd

Please sign in to comment.