Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support parallel execution of cosmos TokenSend txs #3221

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 84 additions & 6 deletions app/app_parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func TestParallelTxs(t *testing.T) {
// ## only cosmos txs ##
// #####################
{
"5 cosmos txs, 0 group: a->b b->c c->d d->e e->f",
"5 cosmos txs, 1 group: a->b b->c c->d d->e e->f",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -443,7 +443,22 @@ func TestParallelTxs(t *testing.T) {
[]uint32{0, 0, 0, 0, 0},
},
{
"4 cosmos txs, 1 Failed cosmos tx, 0 group: a->b failed(b->c) / d->e e->f f->g",
"4 cosmos txs, 1 Failed cosmos tx, 1 group: a->b failed(b->c) b->c c->d d->f",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
rawTxs = append(rawTxs, createTokenSendTx(t, chain, 0))
rawTxs = append(rawTxs, createFailedTokenSendTx(t, chain, 1))
for i := 2; i < 5; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
ret := runTxs(chain, rawTxs, isParallel)
return ret, resultHash(ret), chain.app.BaseApp.LastCommitID().Hash
},
[]uint32{0, 61034, 0, 0, 0},
},
{
"4 cosmos txs, 1 Failed cosmos tx, 2 group: a->b failed(b->c) / d->e e->f f->g",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -458,7 +473,7 @@ func TestParallelTxs(t *testing.T) {
[]uint32{0, 61034, 0, 0, 0},
},
{
"4 cosmos txs, 1 AnteErr cosmos tx, 0 group: a->b AnteErr(b->c) c->d d->e e->f",
"4 cosmos txs, 1 AnteErr cosmos tx, 1 group: a->b AnteErr(b->c) c->d d->e e->f",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -473,7 +488,7 @@ func TestParallelTxs(t *testing.T) {
[]uint32{0, 5, 0, 0, 0},
},
{
"4 failed cosmos txs, 1 AnteErr cosmos tx, 0 group",
"4 failed cosmos txs, 1 AnteErr cosmos tx, 1 group",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -488,7 +503,7 @@ func TestParallelTxs(t *testing.T) {
[]uint32{61034, 5, 61034, 61034, 61034},
},
{
"3 cosmos txs, 1 failed cosmos tx, 1 AnteErr cosmos tx, 0 group: a->b b->c c->d d->e e->f",
"3 cosmos txs, 1 failed cosmos tx, 1 AnteErr cosmos tx, 1 group: a->b b->c c->d d->e e->f",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -504,7 +519,7 @@ func TestParallelTxs(t *testing.T) {
[]uint32{0, 61034, 5, 0, 0},
},
{
"5 failed cosmos txs, 0 group: a->b b->c c->d d->e e->f",
"5 failed cosmos txs, 1 group: a->b b->c c->d d->e e->f",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
Expand All @@ -516,6 +531,69 @@ func TestParallelTxs(t *testing.T) {
},
[]uint32{61034, 61034, 61034, 61034, 61034},
},
{
"5 cosmos txs, 2 group: a->b b->c / d->e e->f f->g",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
for i := 0; i < 2; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
for i := 3; i < 6; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
ret := runTxs(chain, rawTxs, isParallel)
return ret, resultHash(ret), chain.app.BaseApp.LastCommitID().Hash
},
[]uint32{0, 0, 0, 0, 0},
},
{
"4 cosmos txs, 1 AnteErr cosmos tx, 2 group: a->b AnteErr(b->c) / d->e e->f f->g",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
rawTxs = append(rawTxs, createTokenSendTx(t, chain, 0))
rawTxs = append(rawTxs, createAnteErrTokenSendTx(t, chain, 1))
for i := 3; i < 6; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
ret := runTxs(chain, rawTxs, isParallel)
return ret, resultHash(ret), chain.app.BaseApp.LastCommitID().Hash
},
[]uint32{0, 5, 0, 0, 0},
},
{
"3 cosmos txs, 1 failed cosmos tx, 1 AnteErr cosmos tx, 2 group: a->b failed(b->c) / AnteErr(d->e) e->f f->g",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
rawTxs = append(rawTxs, createTokenSendTx(t, chain, 0))
rawTxs = append(rawTxs, createFailedTokenSendTx(t, chain, 1))
rawTxs = append(rawTxs, createAnteErrTokenSendTx(t, chain, 3))
for i := 4; i < 6; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
ret := runTxs(chain, rawTxs, isParallel)
return ret, resultHash(ret), chain.app.BaseApp.LastCommitID().Hash
},
[]uint32{0, 61034, 5, 0, 0},
},
{
"3 cosmos txs, 1 failed cosmos tx, 1 AnteErr cosmos tx, 2 group: a->b failed(b->c) AnteErr(d->e) / e->f f->g",
func(t *testing.T, chain *Chain, isParallel bool) ([]*abci.ResponseDeliverTx, []byte, []byte) {

var rawTxs [][]byte
rawTxs = append(rawTxs, createTokenSendTx(t, chain, 0))
rawTxs = append(rawTxs, createFailedTokenSendTx(t, chain, 1))
rawTxs = append(rawTxs, createAnteErrTokenSendTx(t, chain, 2))
for i := 4; i < 6; i++ {
rawTxs = append(rawTxs, createTokenSendTx(t, chain, i))
}
ret := runTxs(chain, rawTxs, isParallel)
return ret, resultHash(ret), chain.app.BaseApp.LastCommitID().Hash
},
[]uint32{0, 61034, 5, 0, 0},
},
// #####################
// ###### mix txs ######
// #####################
Expand Down
9 changes: 8 additions & 1 deletion x/token/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
package types

import (
"strings"

ethcmm "github.com/ethereum/go-ethereum/common"

sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/x/common"
)
Expand All @@ -14,7 +18,6 @@ const (
TotalSupplyUpperbound = int64(9 * 1e10)
)

//
type MsgTokenIssue struct {
Description string `json:"description"`
Symbol string `json:"symbol"`
Expand Down Expand Up @@ -252,6 +255,10 @@ func (msg MsgSend) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.FromAddress}
}

func (msg MsgSend) CalFromAndToForPara() (string, string) {
return strings.ToLower(ethcmm.BytesToAddress(msg.FromAddress).String()[2:]), strings.ToLower(ethcmm.BytesToAddress(msg.ToAddress).String()[2:])
}

// MsgTransferOwnership - high level transaction of the coin module
type MsgTransferOwnership struct {
FromAddress sdk.AccAddress `json:"from_address"`
Expand Down
Loading