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

Transaction crashing go sdk when calling ID() #631

Closed
austinkline opened this issue Apr 23, 2024 · 2 comments · Fixed by #632
Closed

Transaction crashing go sdk when calling ID() #631

austinkline opened this issue Apr 23, 2024 · 2 comments · Fixed by #632
Assignees

Comments

@austinkline
Copy link

Problem

Transactions can crash the sdk under certain conditions if you call Transaction.ID()

Steps to Reproduce

package main

import (
	"context"
	flowGrpc "github.com/onflow/flow-go-sdk/access/grpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	c, err := flowGrpc.NewClient(
		flowGrpc.MainnetHost,
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(1024*1024*1024)), // 1GB
	)
	if err != nil {
		panic(err)
	}

	ctx := context.Background()

	height := uint64(76751808)
	block, err := c.GetBlockByHeight(ctx, height)
	if err != nil {
		panic(err)
	}

	txns, err := c.GetTransactionsByBlockID(ctx, block.ID)
	if err != nil {
		panic(err)
	}

	for _, txn := range txns {
		// print the ID, one will crash
		println(txn.ID().Hex())
	}
}

Acceptance Criteria

The sdk does not crash

Context

Our backing ingestion system at Flowty ran into this issue.

@austinkline
Copy link
Author

Stack Trace:

panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/onflow/flow-go-sdk.(*Transaction).payloadCanonicalForm(0x1400013e6c0)
        /Users/austinkline/go/pkg/mod/github.com/onflow/[email protected]/transaction.go:383 +0x2a4
github.com/onflow/flow-go-sdk.(*Transaction).Encode(0x1400013e6c0)
        /Users/austinkline/go/pkg/mod/github.com/onflow/[email protected]/transaction.go:423 +0x3c
github.com/onflow/flow-go-sdk.(*Transaction).ID(0x140003522d0?)
        /Users/austinkline/go/pkg/mod/github.com/onflow/[email protected]/transaction.go:126 +0x24
main.main()
        src/crashing-block/main.go:35 +0x2c4

Process finished with the exit code 2

@austinkline austinkline changed the title Transaction crashing go sdk when resolving calling ID() Transaction crashing go sdk when callinging ID() Apr 23, 2024
@austinkline austinkline changed the title Transaction crashing go sdk when callinging ID() Transaction crashing go sdk when calling ID() Apr 23, 2024
@jribbink
Copy link
Contributor

jribbink commented Apr 23, 2024

It has to do with this transaction containing empty arguments when queried from AN. https://rest-mainnet.onflow.org/v1/transactions/3b21d84b3e9c498bb1a9274793b1b3c0d590a6b9c70077b783e846ee9ee548cc

	"arguments": [
		"",
		""
	],

Which causes a panic when this code tries to index & position -1 in an empty array.

flow-go-sdk/transaction.go

Lines 381 to 386 in 05db7e1

// note(sideninja): This is a temporary workaround until cadence defines canonical format addressing the issue https://github.com/onflow/flow-go-sdk/issues/286
for i, arg := range t.Arguments {
if arg[len(arg)-1] == byte(10) { // extra new line character
t.Arguments[i] = arg[:len(arg)-1]
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants