Skip to content

Commit

Permalink
Merge branch 'master' into fixing-partitiontest-check
Browse files Browse the repository at this point in the history
  • Loading branch information
algojack authored Jan 19, 2023
2 parents e1ae7fa + a9fe2c7 commit a9eeead
Show file tree
Hide file tree
Showing 31 changed files with 459 additions and 485 deletions.
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG TARGETARCH
ADD https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz /go.tar.gz

# Basic dependencies.
ENV HOME="/node" DEBIAN_FRONTEND="noninteractive" GOPATH="/node"
ENV HOME="/node" DEBIAN_FRONTEND="noninteractive" GOPATH="/dist"

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand All @@ -27,15 +27,15 @@ RUN apt-get update && \

ENV PATH="/usr/local/go/bin:${PATH}"

COPY ./docker/files/ /node/files
COPY ./installer/genesis /node/files/run/genesis
COPY ./cmd/updater/update.sh /node/files/build/update.sh
COPY ./installer/config.json.example /node/files/run/config.json.example
COPY ./docker/files/ /dist/files
COPY ./installer/genesis /dist/files/run/genesis
COPY ./cmd/updater/update.sh /dist/files/build/update.sh
COPY ./installer/config.json.example /dist/files/run/config.json.example

# Install algod binaries.
RUN /node/files/build/install.sh \
RUN /dist/files/build/install.sh \
-p "${GOPATH}/bin" \
-d "/node/data" \
-d "/algod/data" \
-c "${CHANNEL}" \
-u "${URL}" \
-b "${BRANCH}" \
Expand All @@ -55,10 +55,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates

USER algorand

COPY --chown=algorand:algorand --from=builder "/node/bin/" "/node/bin/"
COPY --chown=algorand:algorand --from=builder "/node/files/run/" "/node/run/"
COPY --chown=algorand:algorand --from=builder "/dist/bin/" "/node/bin/"
COPY --chown=algorand:algorand --from=builder "/dist/files/run/" "/node/run/"

# Expose Algod REST API, Algod Gossip, and Prometheus Metrics ports
EXPOSE $ALGOD_PORT 4160 9100

WORKDIR /algod

CMD ["/node/run/run.sh"]
4 changes: 2 additions & 2 deletions cmd/catchpointdump/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (

"github.com/spf13/cobra"

"github.com/algorand/avm-abi/apps"
cmdutil "github.com/algorand/go-algorand/cmd/util"
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/ledger"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store"
Expand Down Expand Up @@ -436,7 +436,7 @@ func printAccountsDatabase(databaseName string, stagingTables bool, fileHeader l

func printKeyValue(writer *bufio.Writer, key, value []byte) {
var pretty string
ai, rest, err := logic.SplitBoxKey(string(key))
ai, rest, err := apps.SplitBoxKey(string(key))
if err == nil {
pretty = fmt.Sprintf("box(%d, %s)", ai, base64.StdEncoding.EncodeToString([]byte(rest)))
} else {
Expand Down
23 changes: 12 additions & 11 deletions cmd/goal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/spf13/cobra"

"github.com/algorand/avm-abi/abi"
"github.com/algorand/avm-abi/apps"
"github.com/algorand/go-algorand/crypto"
apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/basics"
Expand Down Expand Up @@ -198,25 +199,25 @@ func panicIfErr(err error) {
}
}

func newAppCallBytes(arg string) logic.AppCallBytes {
appBytes, err := logic.NewAppCallBytes(arg)
func newAppCallBytes(arg string) apps.AppCallBytes {
appBytes, err := apps.NewAppCallBytes(arg)
if err != nil {
reportErrorf(err.Error())
}
return appBytes
}

type appCallInputs struct {
Accounts []string `codec:"accounts"`
ForeignApps []uint64 `codec:"foreignapps"`
ForeignAssets []uint64 `codec:"foreignassets"`
Boxes []boxRef `codec:"boxes"`
Args []logic.AppCallBytes `codec:"args"`
Accounts []string `codec:"accounts"`
ForeignApps []uint64 `codec:"foreignapps"`
ForeignAssets []uint64 `codec:"foreignassets"`
Boxes []boxRef `codec:"boxes"`
Args []apps.AppCallBytes `codec:"args"`
}

type boxRef struct {
appID uint64 `codec:"app"`
name logic.AppCallBytes `codec:"name"`
appID uint64 `codec:"app"`
name apps.AppCallBytes `codec:"name"`
}

// newBoxRef parses a command-line box ref, which is an optional appId, a comma,
Expand Down Expand Up @@ -335,7 +336,7 @@ func processAppInputFile() (args [][]byte, accounts []string, foreignApps []uint
return parseAppInputs(inputs)
}

func getAppInputs() (args [][]byte, accounts []string, apps []uint64, assets []uint64, boxes []transactions.BoxRef) {
func getAppInputs() (args [][]byte, accounts []string, _ []uint64, assets []uint64, boxes []transactions.BoxRef) {
if appInputFilename != "" {
if appArgs != nil || appStrAccounts != nil || foreignApps != nil || foreignAssets != nil {
reportErrorf("Cannot specify both command-line arguments/resources and JSON input filename")
Expand All @@ -348,7 +349,7 @@ func getAppInputs() (args [][]byte, accounts []string, apps []uint64, assets []u
// on it. appArgs became `StringArrayVar` in order to support abi arguments
// which contain commas.

var encodedArgs []logic.AppCallBytes
var encodedArgs []apps.AppCallBytes
for _, arg := range appArgs {
if len(arg) > 0 {
encodedArgs = append(encodedArgs, newAppCallBytes(arg))
Expand Down
2 changes: 1 addition & 1 deletion cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ func assembleFileImpl(fname string, printWarnings bool) *logic.OpStream {
}
ops, err := logic.AssembleString(string(text))
if err != nil {
ops.ReportProblems(fname, os.Stderr)
ops.ReportMultipleErrors(fname, os.Stderr)
reportErrorf("%s: %s", fname, err)
}
_, params := getProto(protoVersion)
Expand Down
3 changes: 2 additions & 1 deletion cmd/goal/interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/spf13/cobra"

"github.com/algorand/avm-abi/apps"
"github.com/algorand/go-algorand/crypto"
apiclient "github.com/algorand/go-algorand/daemon/algod/api/client"
"github.com/algorand/go-algorand/data/basics"
Expand Down Expand Up @@ -513,7 +514,7 @@ var appExecuteCmd = &cobra.Command{

var inputs appCallInputs
for _, arg := range proc.Args {
var callArg logic.AppCallBytes
var callArg apps.AppCallBytes
callArg.Encoding = arg.Kind

if !procFlags.Changed(arg.Name) && arg.Default != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/goal/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ var signProgramCmd = &cobra.Command{
}
ops, err := logic.AssembleString(string(text))
if err != nil {
ops.ReportProblems(programSource, os.Stderr)
ops.ReportMultipleErrors(programSource, os.Stderr)
reportErrorf("%s: %s", programSource, err)
}
if outname == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/pingpong/runCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ var runCmd = &cobra.Command{
}
ops, err := logic.AssembleString(programStr)
if err != nil {
ops.ReportProblems(teal, os.Stderr)
ops.ReportMultipleErrors(teal, os.Stderr)
reportErrorf("Internal error, cannot assemble %v \n", programStr)
}
cfg.Program = ops.Program
Expand Down
9 changes: 5 additions & 4 deletions daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/labstack/echo/v4"

"github.com/algorand/avm-abi/apps"
"github.com/algorand/go-codec/codec"

"github.com/algorand/go-algorand/agreement"
Expand Down Expand Up @@ -1382,7 +1383,7 @@ func (v2 *Handlers) GetApplicationBoxes(ctx echo.Context, applicationID uint64,
appIdx := basics.AppIndex(applicationID)
ledger := v2.Node.LedgerForAPI()
lastRound := ledger.Latest()
keyPrefix := logic.MakeBoxKey(appIdx, "")
keyPrefix := apps.MakeBoxKey(uint64(appIdx), "")

requestedMax, algodMax := nilToZero(params.Max), v2.Node.Config().MaxAPIBoxPerApplication
max := applicationBoxesMaxKeys(requestedMax, algodMax)
Expand Down Expand Up @@ -1428,7 +1429,7 @@ func (v2 *Handlers) GetApplicationBoxByName(ctx echo.Context, applicationID uint
lastRound := ledger.Latest()

encodedBoxName := params.Name
boxNameBytes, err := logic.NewAppCallBytes(encodedBoxName)
boxNameBytes, err := apps.NewAppCallBytes(encodedBoxName)
if err != nil {
return badRequest(ctx, err, err.Error(), v2.Log)
}
Expand All @@ -1437,7 +1438,7 @@ func (v2 *Handlers) GetApplicationBoxByName(ctx echo.Context, applicationID uint
return badRequest(ctx, err, err.Error(), v2.Log)
}

value, err := ledger.LookupKv(lastRound, logic.MakeBoxKey(appIdx, string(boxName)))
value, err := ledger.LookupKv(lastRound, apps.MakeBoxKey(uint64(appIdx), string(boxName)))
if err != nil {
return internalError(ctx, err, errFailedLookingUpLedger, v2.Log)
}
Expand Down Expand Up @@ -1528,7 +1529,7 @@ func (v2 *Handlers) TealCompile(ctx echo.Context, params model.TealCompileParams
ops, err := logic.AssembleString(source)
if err != nil {
sb := strings.Builder{}
ops.ReportProblems("", &sb)
ops.ReportMultipleErrors("", &sb)
return badRequest(ctx, err, sb.String(), v2.Log)
}
pd := logic.HashProgram(ops.Program)
Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/test/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ func TestTealCompile(t *testing.T) {
t.Parallel()

params := model.TealCompileParams{}
tealCompileTest(t, nil, 200, true, params, nil) // nil program should work
tealCompileTest(t, nil, 400, true, params, nil) // nil program should NOT work

goodProgram := fmt.Sprintf(`#pragma version %d
int 1
Expand Down
22 changes: 18 additions & 4 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ func isFullSpec(spec OpSpec) bool {
}

// mergeProtos allows us to support typetracking of pseudo-ops which are given an improper number of immediates
//by creating a new proto that is a combination of all the pseudo-op's possibilities
// by creating a new proto that is a combination of all the pseudo-op's possibilities
func mergeProtos(specs map[int]OpSpec) (Proto, uint64, bool) {
var args StackTypes
var returns StackTypes
Expand Down Expand Up @@ -1857,10 +1857,13 @@ func splitTokens(tokens []string) (current, rest []string) {

// assemble reads text from an input and accumulates the program
func (ops *OpStream) assemble(text string) error {
fin := strings.NewReader(text)
if ops.Version > LogicVersion && ops.Version != assemblerNoVersion {
return ops.errorf("Can not assemble version %d", ops.Version)
}
if strings.TrimSpace(text) == "" {
return ops.errorf("Cannot assemble empty program text")
}
fin := strings.NewReader(text)
scanner := bufio.NewScanner(fin)
for scanner.Scan() {
ops.sourceLine++
Expand Down Expand Up @@ -2411,8 +2414,19 @@ func (ops *OpStream) warnf(format string, a ...interface{}) error {
return ops.warn(fmt.Errorf(format, a...))
}

// ReportProblems issues accumulated warnings and outputs errors to an io.Writer.
func (ops *OpStream) ReportProblems(fname string, writer io.Writer) {
// ReportMultipleErrors issues accumulated warnings and outputs errors to an io.Writer.
// In the case of exactly 1 error and no warnings, a slightly different format is provided
// to handle the cases when the original error is or isn't reported elsewhere.
// In the case of > 10 errors, only the first 10 errors will be reported.
func (ops *OpStream) ReportMultipleErrors(fname string, writer io.Writer) {
if len(ops.Errors) == 1 && len(ops.Warnings) == 0 {
prefix := ""
if fname != "" {
prefix = fmt.Sprintf("%s: ", fname)
}
fmt.Fprintf(writer, "%s1 error: %s\n", prefix, ops.Errors[0])
return
}
for i, e := range ops.Errors {
if i > 9 {
break
Expand Down
108 changes: 107 additions & 1 deletion data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package logic
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -1457,7 +1458,7 @@ done:`
require.Equal(t, expectedProgBytes, ops.Program)
}

func TestMultipleErrors(t *testing.T) {
func TestSeveralErrors(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

Expand Down Expand Up @@ -3053,3 +3054,108 @@ func TestAssemblePushConsts(t *testing.T) {
source = `pushbytess "x" "y"; +`
testProg(t, source, AssemblerMaxVersion, Expect{1, "+ arg 1 wanted type uint64 got []byte"})
}

func TestAssembleEmpty(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

emptyExpect := Expect{0, "Cannot assemble empty program text"}
emptyPrograms := []string{
"",
" ",
" \n\t\t\t\n\n ",
" \n \t \t \t \n \n \n\n",
}

nonEmpty := " \n \t \t \t int 1 \n \n \t \t \n\n"

for version := uint64(1); version <= AssemblerMaxVersion; version++ {
for _, prog := range emptyPrograms {
testProg(t, prog, version, emptyExpect)
}
testProg(t, nonEmpty, version)
}
}

func TestReportMultipleErrors(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

assertWithMsg := func(t *testing.T, expectedOutput string, b bytes.Buffer) {
if b.String() != expectedOutput {
t.Errorf("Unexpected output: got %q, want %q", b.String(), expectedOutput)
}
}

ops := &OpStream{
Errors: []lineError{
{Line: 1, Err: errors.New("error 1")},
{Err: errors.New("error 2")},
{Line: 3, Err: errors.New("error 3")},
},
Warnings: []error{
errors.New("warning 1"),
errors.New("warning 2"),
},
}

// Test the case where fname is not empty
var b bytes.Buffer
ops.ReportMultipleErrors("test.txt", &b)
expected := `test.txt: 1: error 1
test.txt: 0: error 2
test.txt: 3: error 3
test.txt: warning 1
test.txt: warning 2
`
assertWithMsg(t, expected, b)

// Test the case where fname is empty
b.Reset()
ops.ReportMultipleErrors("", &b)
expected = `1: error 1
0: error 2
3: error 3
warning 1
warning 2
`
assertWithMsg(t, expected, b)

// no errors or warnings at all
ops = &OpStream{}
b.Reset()
ops.ReportMultipleErrors("blah blah", &b)
expected = ""
assertWithMsg(t, expected, b)

// more than 10 errors:
file := "great-file.go"
les := []lineError{}
expectedStrs := []string{}
for i := 1; i <= 11; i++ {
errS := fmt.Errorf("error %d", i)
les = append(les, lineError{i, errS})
if i <= 10 {
expectedStrs = append(expectedStrs, fmt.Sprintf("%s: %d: %s", file, i, errS))
}
}
expected = strings.Join(expectedStrs, "\n") + "\n"
ops = &OpStream{Errors: les}
b.Reset()
ops.ReportMultipleErrors(file, &b)
assertWithMsg(t, expected, b)

// exactly 1 error + filename
ops = &OpStream{Errors: []lineError{{42, errors.New("super annoying error")}}}
b.Reset()
ops.ReportMultipleErrors("galaxy.py", &b)
expected = "galaxy.py: 1 error: 42: super annoying error\n"
assertWithMsg(t, expected, b)

// exactly 1 error w/o filename
ops = &OpStream{Errors: []lineError{{42, errors.New("super annoying error")}}}
b.Reset()
ops.ReportMultipleErrors("", &b)
expected = "1 error: 42: super annoying error\n"
assertWithMsg(t, expected, b)
}
Loading

0 comments on commit a9eeead

Please sign in to comment.