Skip to content

Commit 01037ec

Browse files
committed
Merge branch 'master' into optimize-circleci-upload-stage
2 parents 6d144ff + 78317e8 commit 01037ec

File tree

7 files changed

+102
-12
lines changed

7 files changed

+102
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ executors:
4848

4949
workflows:
5050
version: 2
51-
build_pr:
51+
"circleci_build_and_test":
5252
jobs:
5353
- codegen_verification
5454

data/transactions/logic/assembler.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,16 @@ func asmPushInt(ops *OpStream, spec *OpSpec, args []string) error {
472472
return nil
473473
}
474474
func asmPushBytes(ops *OpStream, spec *OpSpec, args []string) error {
475-
if len(args) != 1 {
476-
return ops.errorf("%s needs one argument", spec.Name)
475+
if len(args) == 0 {
476+
return ops.errorf("%s operation needs byte literal argument", spec.Name)
477477
}
478-
val, _, err := parseBinaryArgs(args)
478+
val, consumed, err := parseBinaryArgs(args)
479479
if err != nil {
480480
return ops.error(err)
481481
}
482+
if len(args) != consumed {
483+
return ops.errorf("%s operation with extraneous argument", spec.Name)
484+
}
482485
ops.pending.WriteByte(spec.Opcode)
483486
var scratch [binary.MaxVarintLen64]byte
484487
vlen := binary.PutUvarint(scratch[:], uint64(len(val)))
@@ -636,12 +639,15 @@ func parseStringLiteral(input string) (result []byte, err error) {
636639
// byte "this is a string\n"
637640
func assembleByte(ops *OpStream, spec *OpSpec, args []string) error {
638641
if len(args) == 0 {
639-
return ops.error("byte operation needs byte literal argument")
642+
return ops.errorf("%s operation needs byte literal argument", spec.Name)
640643
}
641-
val, _, err := parseBinaryArgs(args)
644+
val, consumed, err := parseBinaryArgs(args)
642645
if err != nil {
643646
return ops.error(err)
644647
}
648+
if len(args) != consumed {
649+
return ops.errorf("%s operation with extraneous argument", spec.Name)
650+
}
645651
ops.ByteLiteral(val)
646652
return nil
647653
}

data/transactions/logic/assembler_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ func testProg(t testing.TB, source string, ver uint64, expected ...expect) *OpSt
475475
require.NoError(t, err)
476476
require.Equal(t, ops.Program, ops2.Program)
477477
} else {
478+
if err == nil {
479+
t.Log(program)
480+
}
478481
require.Error(t, err)
479482
errors := ops.Errors
480483
for _, exp := range expected {
@@ -507,6 +510,7 @@ func testProg(t testing.TB, source string, ver uint64, expected ...expect) *OpSt
507510
}
508511

509512
func testLine(t *testing.T, line string, ver uint64, expected string) {
513+
t.Helper()
510514
// By embedding the source line between two other lines, the
511515
// test for the correct line number in the error is more
512516
// meaningful.
@@ -517,6 +521,7 @@ func testLine(t *testing.T, line string, ver uint64, expected string) {
517521
}
518522
testProg(t, source, ver, expect{2, expected})
519523
}
524+
520525
func TestAssembleTxna(t *testing.T) {
521526
partitiontest.PartitionTest(t)
522527

@@ -661,6 +666,7 @@ func TestAssembleBytes(t *testing.T) {
661666
variations := []string{
662667
"byte b32 MFRGGZDFMY",
663668
"byte base32 MFRGGZDFMY",
669+
"byte base32 MFRGGZDFMY",
664670
"byte base32(MFRGGZDFMY)",
665671
"byte b32(MFRGGZDFMY)",
666672
"byte b32 MFRGGZDFMY======",
@@ -679,6 +685,11 @@ func TestAssembleBytes(t *testing.T) {
679685
expectedDefaultConsts := "0126010661626364656628"
680686
expectedOptimizedConsts := "018006616263646566"
681687

688+
bad := [][]string{
689+
{"byte", "...operation needs byte literal argument"},
690+
{`byte "john" "doe"`, "...operation with extraneous argument"},
691+
}
692+
682693
for v := uint64(1); v <= AssemblerMaxVersion; v++ {
683694
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) {
684695
expected := expectedDefaultConsts
@@ -690,8 +701,19 @@ func TestAssembleBytes(t *testing.T) {
690701
ops := testProg(t, vi, v)
691702
s := hex.EncodeToString(ops.Program)
692703
require.Equal(t, mutateProgVersion(v, expected), s)
704+
// pushbytes should take the same input
705+
if v >= 3 {
706+
testProg(t, strings.Replace(vi, "byte", "pushbytes", 1), v)
707+
}
693708
}
694709

710+
for _, b := range bad {
711+
testProg(t, b[0], v, expect{1, b[1]})
712+
// pushbytes should produce the same errors
713+
if v >= 3 {
714+
testProg(t, strings.Replace(b[0], "byte", "pushbytes", 1), v, expect{1, b[1]})
715+
}
716+
}
695717
})
696718
}
697719
}
@@ -1448,7 +1470,7 @@ func TestConstantArgs(t *testing.T) {
14481470
}
14491471
for v := uint64(3); v <= AssemblerMaxVersion; v++ {
14501472
testProg(t, "pushint", v, expect{1, "pushint needs one argument"})
1451-
testProg(t, "pushbytes", v, expect{1, "pushbytes needs one argument"})
1473+
testProg(t, "pushbytes", v, expect{1, "pushbytes operation needs byte literal argument"})
14521474
}
14531475

14541476
}

data/transactions/teal.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ type EvalDelta struct {
3737

3838
Logs []string `codec:"lg,allocbound=config.MaxLogCalls"`
3939

40-
// Intentionally, temporarily wrong - need to decide how to
41-
// allocbound properly when structure is recursive. Even a bound
42-
// of 2 would allow arbitrarily large object if deep.
4340
InnerTxns []SignedTxnWithAD `codec:"itx,allocbound=config.MaxInnerTransactions"`
4441
}
4542

data/txHandler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ func (handler *solicitedAsyncTxHandler) HandleTransactionGroups(networkPeer inte
502502

503503
func (handler *solicitedAsyncTxHandler) Start() {
504504
if handler.stopCtxFunc == nil {
505+
handler.txHandler.Start()
505506
var ctx context.Context
506507
ctx, handler.stopCtxFunc = context.WithCancel(context.Background())
507508
handler.stopped.Add(1)
@@ -514,6 +515,7 @@ func (handler *solicitedAsyncTxHandler) Stop() {
514515
handler.stopCtxFunc()
515516
handler.stopped.Wait()
516517
handler.stopCtxFunc = nil
518+
handler.txHandler.Stop()
517519
}
518520
}
519521

network/wsNetwork.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,21 @@ func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *htt
11441144

11451145
// We are careful to encode this prior to starting the server to avoid needing 'messagesOfInterestMu' here.
11461146
if wn.messagesOfInterestEnc != nil {
1147-
err = peer.Unicast(wn.ctx, wn.messagesOfInterestEnc, protocol.MsgOfInterestTag, nil)
1147+
msg := wn.messagesOfInterestEnc
1148+
// for older peers, we want to include also the "TX" message, for backward compatibility.
1149+
// this statement could be safely removed once we've fully migrated.
1150+
if peer.version == "2.1" {
1151+
wn.messagesOfInterestMu.Lock()
1152+
txSendMsgTags := make(map[protocol.Tag]bool)
1153+
for tag := range wn.messagesOfInterest {
1154+
txSendMsgTags[tag] = true
1155+
}
1156+
wn.messagesOfInterestMu.Unlock()
1157+
txSendMsgTags[protocol.TxnTag] = true
1158+
msg = MarshallMessageOfInterestMap(txSendMsgTags)
1159+
}
1160+
err = peer.Unicast(wn.ctx, msg, protocol.MsgOfInterestTag, nil)
1161+
11481162
if err != nil {
11491163
wn.log.Infof("ws send msgOfInterest: %v", err)
11501164
}

test/e2e-go/features/transactions/sendReceive_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package transactions
1818

1919
import (
20+
"fmt"
2021
"math/rand"
2122
"path/filepath"
2223
"testing"
2324

2425
"github.com/stretchr/testify/require"
2526

27+
"github.com/algorand/go-algorand/config"
2628
v1 "github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
2729
"github.com/algorand/go-algorand/test/framework/fixtures"
2830
"github.com/algorand/go-algorand/test/partitiontest"
@@ -66,11 +68,16 @@ func TestDevModeAccountsCanSendMoney(t *testing.T) {
6668

6769
func testAccountsCanSendMoney(t *testing.T, templatePath string, numberOfSends int) {
6870
t.Parallel()
69-
a := require.New(fixtures.SynchronizedTest(t))
7071

7172
var fixture fixtures.RestClientFixture
7273
fixture.Setup(t, templatePath)
7374
defer fixture.Shutdown()
75+
testAccountsCanSendMoneyFixture(t, &fixture, numberOfSends)
76+
}
77+
78+
func testAccountsCanSendMoneyFixture(t *testing.T, fixture *fixtures.RestClientFixture, numberOfSends int) {
79+
a := require.New(fixtures.SynchronizedTest(t))
80+
7481
c := fixture.LibGoalClient
7582

7683
pingClient := fixture.LibGoalClient
@@ -159,3 +166,45 @@ func testAccountsCanSendMoney(t *testing.T, templatePath string, numberOfSends i
159166
a.True(expectedPingBalance <= pingBalance, "ping balance is different than expected.")
160167
a.True(expectedPongBalance <= pongBalance, "pong balance is different than expected.")
161168
}
169+
170+
// this test checks that two accounts' balances stay up to date
171+
// as they send each other money many times
172+
func TestAccountsCanSendMoneyAcrossTxSync(t *testing.T) {
173+
partitiontest.PartitionTest(t)
174+
defer fixtures.ShutdownSynchronizedTest(t)
175+
176+
numberOfSends := 3
177+
a := require.New(fixtures.SynchronizedTest(t))
178+
179+
networkProtocolVersions := []string{"3.0", "2.1"}
180+
181+
testMoneySending := func(t *testing.T, primaryNodeVersionIdx, nodeVersionIdx int) {
182+
t.Run(fmt.Sprintf("%s->%s", networkProtocolVersions[primaryNodeVersionIdx], networkProtocolVersions[nodeVersionIdx]),
183+
func(t *testing.T) {
184+
t.Parallel()
185+
var fixture fixtures.RestClientFixture
186+
fixture.SetupNoStart(t, filepath.Join("nettemplates", "TwoNodes50Each.json"))
187+
defer fixture.Shutdown()
188+
189+
cfg, err := config.LoadConfigFromDisk(fixture.PrimaryDataDir())
190+
a.NoError(err)
191+
cfg.NetworkProtocolVersion = networkProtocolVersions[primaryNodeVersionIdx]
192+
cfg.SaveToDisk(fixture.PrimaryDataDir())
193+
194+
cfg, err = config.LoadConfigFromDisk(fixture.NodeDataDirs()[0])
195+
a.NoError(err)
196+
cfg.NetworkProtocolVersion = networkProtocolVersions[primaryNodeVersionIdx]
197+
cfg.SaveToDisk(fixture.NodeDataDirs()[0])
198+
199+
fixture.Start()
200+
testAccountsCanSendMoneyFixture(t, &fixture, numberOfSends)
201+
})
202+
}
203+
204+
// test to see that we can communicate correctly regardless of the network protocol version.
205+
for primaryNodeVersionIdx := 0; primaryNodeVersionIdx < 2; primaryNodeVersionIdx++ {
206+
for nodeVersionIdx := 0; nodeVersionIdx < 2; nodeVersionIdx++ {
207+
testMoneySending(t, primaryNodeVersionIdx, nodeVersionIdx)
208+
}
209+
}
210+
}

0 commit comments

Comments
 (0)