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

fix: attempt to fix tx inclusion timeout #171

Merged
merged 7 commits into from
Nov 24, 2021
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ ifeq ($(EXPERIMENTAL),true)
TEST_RACE_ARGS += experimental
endif

test-unit: ARGS=-tags='$(UNIT_TEST_ARGS)'
test-unit: ARGS=-count=1 -tags='$(UNIT_TEST_ARGS)'
test-unit-amino: ARGS=-tags='${AMINO_TEST_ARGS}'
test-ledger: ARGS=-tags='${LEDGER_TEST_ARGS}'
test-ledger-mock: ARGS=-tags='${LEDGER_MOCK_ARGS}'
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8 // indirect
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211115160612-a5da7257a6f7
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.27.1
pgregory.net/rapid v0.4.7
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8 h1:5QRxNnVsaJP6NAse0UdkRgL3zHMvCRRkrDVLNdNpdy4=
golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 h1:/pEO3GD/ABYAjuakUS6xSEmmlyVS4kxBNkeA9tLJiTI=
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -901,8 +901,9 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f h1:w6wWR0H+nyVpbSAQbzVEIACVyr/h8l/BEkY6Sokc7Eg=
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1189,8 +1190,8 @@ google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKr
google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w=
google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20211115160612-a5da7257a6f7 h1:0LoCYJF53PEqtJOntKxGD72X/c8Xto5EZ4HLrt9D80I=
google.golang.org/genproto v0.0.0-20211115160612-a5da7257a6f7/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 h1:b9mVrqYfq3P4bCdaLg1qtBnPzUYgglsIdjZkL/fQVOE=
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand Down
4 changes: 3 additions & 1 deletion orm/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func (a table) Set(ctx HasKVStore, rowID RowID, newValue codec.ProtoMarshaler) e
var oldValue codec.ProtoMarshaler
if a.Has(ctx, rowID) {
oldValue = reflect.New(a.model).Interface().(codec.ProtoMarshaler)
a.GetOne(ctx, rowID, oldValue)
if err := a.GetOne(ctx, rowID, oldValue); err != nil {
return err
}
}

newValueEncoded, err := a.cdc.MarshalBinaryBare(newValue)
Expand Down
9 changes: 7 additions & 2 deletions proto/fetchai/group/v1alpha1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,15 @@ message Vote {
google.protobuf.Timestamp submitted_at = 5 [(gogoproto.nullable) = false];
}

// TallyPoll represents the sum of weighted votes for a poll.
message TallyPoll {
option (gogoproto.goproto_getters) = false;
map<string, string> counts = 1;
repeated TallyPollEntry entries = 1;
}

message TallyPollEntry {
option (gogoproto.goproto_getters) = false;
string option_title = 1;
string weight = 2;
}

// Options represents the choices voters can vote for a poll.
Expand Down
49 changes: 30 additions & 19 deletions x/group/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ func (s *IntegrationTestSuite) TestTxCreateGroup() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -666,7 +665,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupAdmin() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -753,7 +751,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMetadata() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -876,7 +873,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupMembers() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1001,7 +997,6 @@ func (s *IntegrationTestSuite) TestTxCreateGroupAccount() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1105,7 +1100,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupAccountAdmin() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1209,7 +1203,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupAccountDecisionPolicy() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1328,7 +1321,6 @@ func (s *IntegrationTestSuite) TestTxUpdateGroupAccountMetadata() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1529,7 +1521,6 @@ func (s *IntegrationTestSuite) TestTxCreateProposal() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1718,7 +1709,6 @@ func (s *IntegrationTestSuite) TestTxVote() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -1771,7 +1761,6 @@ func (s *IntegrationTestSuite) TestTxVoteAgg() {
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &txResp), out.String())
s.Require().Equal(uint32(0), txResp.Code, out.String())
s.network.WaitForNextBlock()

voteFlags := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
Expand Down Expand Up @@ -1996,7 +1985,6 @@ func (s *IntegrationTestSuite) TestTxExec() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -2199,7 +2187,6 @@ func (s *IntegrationTestSuite) TestTxCreatePoll() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand All @@ -2218,6 +2205,29 @@ func (s *IntegrationTestSuite) TestTxVotePoll() {
s.Require().NoError(err)
aliceAddr := sdk.AccAddress(aliceInfo.GetPubKey().Address())

now := time.Now()
deadline := now.Add(time.Second * 3000)
timeout, err := gogotypes.TimestampProto(deadline)
s.Require().NoError(err)
timeoutStr := timeout.String()

// create a valid poll
cmd := client.MsgCreatePollCmd()
out, err := cli.ExecTestCLICmd(clientCtx, cmd, append([]string{
aliceAddr.String(),
"2",
"2023 Election",
"alice,bob,charlie,eva",
"2",
timeoutStr,
validMetadata,
}, commonFlags...))
s.Require().NoError(err, out.String())
resp := &sdk.TxResponse{}
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), resp), out.String())
s.Require().Equal(uint32(0), resp.Code, out.String())
validPollID := strings.Trim(resp.Logs[0].Events[0].Attributes[0].Value, "\"")

testCases := []struct {
name string
args []string
Expand All @@ -2230,7 +2240,7 @@ func (s *IntegrationTestSuite) TestTxVotePoll() {
"correct data",
append(
[]string{
"2",
validPollID,
aliceAddr.String(),
"alice,bob",
"",
Expand Down Expand Up @@ -2294,7 +2304,6 @@ func (s *IntegrationTestSuite) TestTxVotePoll() {

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := client.MsgVotePollCmd()

Expand All @@ -2308,7 +2317,6 @@ func (s *IntegrationTestSuite) TestTxVotePoll() {
txResp := tc.respType.(*sdk.TxResponse)
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
}
s.Require().NoError(s.network.WaitForNextBlock())
})
}
}
Expand Down Expand Up @@ -2375,7 +2383,7 @@ func (s *IntegrationTestSuite) TestTxVotePollAgg() {
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}

pollID := "3"
pollID := strings.Trim(txResp.Logs[0].Events[0].Attributes[0].Value, "\"")

// basic vote from alice
cmd = client.GetVotePollBasicCmd()
Expand Down Expand Up @@ -2465,8 +2473,11 @@ func (s *IntegrationTestSuite) TestTxVotePollAgg() {
s.Require().NoError(err, out.String())
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(out.Bytes(), &pollRes))
s.Require().Equal(pollRes.Poll.Status, group.PollStatusSubmitted)
s.Require().Equal(pollRes.Poll.VoteState.Counts, map[string]string{
"alice": "1", "bob": "2", "david": "6", "eva": "4",
s.Require().Equal(pollRes.Poll.VoteState.Entries, []*group.TallyPollEntry{
{OptionTitle: "alice", Weight: "1"},
{OptionTitle: "bob", Weight: "2"},
{OptionTitle: "david", Weight: "6"},
{OptionTitle: "eva", Weight: "4"},
})

// test invalid
Expand Down
64 changes: 18 additions & 46 deletions x/group/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,29 +814,8 @@ Parameters:
}

// make sure group members are sorted by their addresses
sorted := sort.SliceIsSorted(groupMembers, func(i, j int) bool {
addri, err := sdk.AccAddressFromBech32(groupMembers[i].Member.Address)
if err != nil {
panic(err)
}
addrj, err := sdk.AccAddressFromBech32(groupMembers[j].Member.Address)
if err != nil {
panic(err)
}
return bytes.Compare(addri, addrj) < 0
})
if !sorted {
sort.Slice(groupMembers, func(i, j int) bool {
addri, err := sdk.AccAddressFromBech32(groupMembers[i].Member.Address)
if err != nil {
panic(err)
}
addrj, err := sdk.AccAddressFromBech32(groupMembers[j].Member.Address)
if err != nil {
panic(err)
}
return bytes.Compare(addri, addrj) < 0
})
if !sort.SliceIsSorted(groupMembers, sortGroupMembersFunc(groupMembers)) {
sort.SliceStable(groupMembers, sortGroupMembersFunc(groupMembers))
}

index := make(map[string]int, len(groupMembers))
Expand Down Expand Up @@ -1023,29 +1002,8 @@ Parameters:
}

// make sure group members are sorted by their addresses
sorted := sort.SliceIsSorted(groupMembers, func(i, j int) bool {
addri, err := sdk.AccAddressFromBech32(groupMembers[i].Member.Address)
if err != nil {
panic(err)
}
addrj, err := sdk.AccAddressFromBech32(groupMembers[j].Member.Address)
if err != nil {
panic(err)
}
return bytes.Compare(addri, addrj) < 0
})
if !sorted {
sort.Slice(groupMembers, func(i, j int) bool {
addri, err := sdk.AccAddressFromBech32(groupMembers[i].Member.Address)
if err != nil {
panic(err)
}
addrj, err := sdk.AccAddressFromBech32(groupMembers[j].Member.Address)
if err != nil {
panic(err)
}
return bytes.Compare(addri, addrj) < 0
})
if !sort.SliceIsSorted(groupMembers, sortGroupMembersFunc(groupMembers)) {
sort.SliceStable(groupMembers, sortGroupMembersFunc(groupMembers))
}

index := make(map[string]int, len(groupMembers))
Expand Down Expand Up @@ -1381,3 +1339,17 @@ Parameters:

return cmd
}

func sortGroupMembersFunc(groupMembers []*group.GroupMember) func(i, j int) bool {
return func(i, j int) bool {
addri, err := sdk.AccAddressFromBech32(groupMembers[i].Member.Address)
if err != nil {
panic(err)
}
addrj, err := sdk.AccAddressFromBech32(groupMembers[j].Member.Address)
if err != nil {
panic(err)
}
return bytes.Compare(addri, addrj) < 0
}
}
6 changes: 3 additions & 3 deletions x/group/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,9 @@ func (m MsgVotePollBasicResponse) VerifySignature() error {
}

// todo: repeated public keys can be coalesced in pairings
var pkss [][]*bls12381.PubKey
for _ = range m.Options.Titles {
pkss = append(pkss, []*bls12381.PubKey{pkBls})
pkss := make([][]*bls12381.PubKey, len(m.Options.Titles))
for i := range m.Options.Titles {
pkss[i] = []*bls12381.PubKey{pkBls}
}

if err := bls12381.VerifyAggregateSignature(msgsBytes, false, m.Sig, pkss); err != nil {
Expand Down
Loading