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

New Feature: Removes logic dependency #1363

Conversation

AlgoStephenAkiki
Copy link
Contributor

Resolves #1328

Removes the logic dependency from the indexer with the exception of AssembleStringWithVersion in account_testutil.go

Summary

Explain the goal of this change and what problem it is solving. Format this cleanly so that it may be used for a commit message, as your changes will be squash-merged.

Test Plan

How did you test these changes? Please provide the exact scenarios you tested in as much detail as possible including commands, output and rationale.

@AlgoStephenAkiki AlgoStephenAkiki linked an issue Dec 2, 2022 that may be closed by this pull request
@AlgoStephenAkiki AlgoStephenAkiki force-pushed the 1328-remove-go-algoranddatatransactionslogic-dependency branch 2 times, most recently from 48e5709 to 5daadb4 Compare December 2, 2022 21:42
@@ -216,6 +216,7 @@ func MakeCreateAppTxn(sender basics.Address) transactions.SignedTxnWithAD {
// MakeComplexCreateAppTxn makes a transaction that creates an arbitrary app. When assemblerVersion is set to 0, use the AssemblerDefaultVersion.
func MakeComplexCreateAppTxn(sender basics.Address, approval, clear string, assemblerVersion uint64) (transactions.SignedTxnWithAD, error) {
// Create a transaction with ExtraProgramPages field set to 1
// TODO how to handle this?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shiqizng @winder This function complies teal programs from strings. Is this a function that needs to be refactored or replaced completely? It currently is only used in testing in Indexer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method needs to use the new logic package which should include methods like AssembleStringWithVersion and AssembleString

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not ideal to change this method to take raw teal bytes since this would require users to first compile their teal program using something like goal then copy the bytes to the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that would require copying the entire teal assembler into this program?

I'm generally expecting that all of these Make*Txn functions need to be replaced with Make*StateDelta (or Add*ToStateDelta) to accommodate the new interfaces. So this may end up being a non-issue with some of the followup work.

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we need the following functions, not the entire logic package:

// MakeBoxKey creates the key that a box named `name` under app `appIdx` should use.
func MakeBoxKey(appIdx basics.AppIndex, name string) string {
	/* This format is chosen so that a simple indexing scheme on the key would
	   allow for quick lookups of all the boxes of a certain app, or even all
	   the boxes of a certain app with a certain prefix.

	   The "bx:" prefix is so that the kvstore might be usable for things
	   besides boxes.
	*/
	key := make([]byte, boxNameIndex+len(name))
	copy(key, boxPrefix)
	binary.BigEndian.PutUint64(key[boxPrefixLength:], uint64(appIdx))
	copy(key[boxNameIndex:], name)
	return string(key)
}

// SplitBoxKey extracts an appid and box name from a string that was created by MakeBoxKey()
func SplitBoxKey(key string) (basics.AppIndex, string, error) {
	if len(key) < boxNameIndex {
		return 0, "", fmt.Errorf("SplitBoxKey() cannot extract AppIndex as key (%s) too short (length=%d)", key, len(key))
	}
	if key[:boxPrefixLength] != boxPrefix {
		return 0, "", fmt.Errorf("SplitBoxKey() illegal app box prefix in key (%s). Expected prefix '%s'", key, boxPrefix)
	}
	keyBytes := []byte(key)
	app := basics.AppIndex(binary.BigEndian.Uint64(keyBytes[boxPrefixLength:boxNameIndex]))
	return app, key[boxNameIndex:], nil
}

// AppCallBytes represents an encoding and a value of an app call argument.
type AppCallBytes struct {
	Encoding string `codec:"encoding"`
	Value    string `codec:"value"`
}

// NewAppCallBytes parses an argument of the form "encoding:value" to AppCallBytes.
func NewAppCallBytes(arg string) (AppCallBytes, error) {
	parts := strings.SplitN(arg, ":", 2)
	if len(parts) != 2 {
		return AppCallBytes{}, fmt.Errorf("all arguments and box names should be of the form 'encoding:value'")
	}
	return AppCallBytes{
		Encoding: parts[0],
		Value:    parts[1],
	}, nil
}

@AlgoStephenAkiki
Copy link
Contributor Author

AFAIK we need the following functions, not the entire logic package:

// MakeBoxKey creates the key that a box named `name` under app `appIdx` should use.
func MakeBoxKey(appIdx basics.AppIndex, name string) string {
	/* This format is chosen so that a simple indexing scheme on the key would
	   allow for quick lookups of all the boxes of a certain app, or even all
	   the boxes of a certain app with a certain prefix.

	   The "bx:" prefix is so that the kvstore might be usable for things
	   besides boxes.
	*/
	key := make([]byte, boxNameIndex+len(name))
	copy(key, boxPrefix)
	binary.BigEndian.PutUint64(key[boxPrefixLength:], uint64(appIdx))
	copy(key[boxNameIndex:], name)
	return string(key)
}

// SplitBoxKey extracts an appid and box name from a string that was created by MakeBoxKey()
func SplitBoxKey(key string) (basics.AppIndex, string, error) {
	if len(key) < boxNameIndex {
		return 0, "", fmt.Errorf("SplitBoxKey() cannot extract AppIndex as key (%s) too short (length=%d)", key, len(key))
	}
	if key[:boxPrefixLength] != boxPrefix {
		return 0, "", fmt.Errorf("SplitBoxKey() illegal app box prefix in key (%s). Expected prefix '%s'", key, boxPrefix)
	}
	keyBytes := []byte(key)
	app := basics.AppIndex(binary.BigEndian.Uint64(keyBytes[boxPrefixLength:boxNameIndex]))
	return app, key[boxNameIndex:], nil
}

// AppCallBytes represents an encoding and a value of an app call argument.
type AppCallBytes struct {
	Encoding string `codec:"encoding"`
	Value    string `codec:"value"`
}

// NewAppCallBytes parses an argument of the form "encoding:value" to AppCallBytes.
func NewAppCallBytes(arg string) (AppCallBytes, error) {
	parts := strings.SplitN(arg, ":", 2)
	if len(parts) != 2 {
		return AppCallBytes{}, fmt.Errorf("all arguments and box names should be of the form 'encoding:value'")
	}
	return AppCallBytes{
		Encoding: parts[0],
		Value:    parts[1],
	}, nil
}

The AppCallBytes struct requires the Raw() method in handlers LookupApplicationBoxByIDAndName and SearchForApplicationBoxes. If we don't pull the struct over then we still maintain a link to the original package which is why I've pulled over as much of the logic package as I have.

I also pulled out the basics package to try and remove more dependencies with these functions but we can curtail that if you want.

Copy link
Contributor

@Eric-Warehime Eric-Warehime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need any of the abi/ code redefined since this package was already pulled into a separate repo which should be usable as a dependency.

https://github.com/algorand/avm-abi

@winder
Copy link
Contributor

winder commented Dec 5, 2022

Should these go in avm-abi?

@@ -96,7 +97,7 @@ func setupLiveBoxes(t *testing.T, proc func(cert *rpcs.EncodedBlockCert) error,
newBoxValue := "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
boxTxns := make([]*transactions.SignedTxnWithAD, 0)
for _, boxName := range boxNames {
expectedAppBoxes[firstAppid][logic.MakeBoxKey(firstAppid, boxName)] = newBoxValue
expectedAppBoxes[firstAppid][logic.MakeBoxKey(indexerBasics.AppIndex(firstAppid), boxName)] = newBoxValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdk has AppIndex. reuse types from sdk whenever possible.

@AlgoStephenAkiki AlgoStephenAkiki force-pushed the 1328-remove-go-algoranddatatransactionslogic-dependency branch from 58f3dd8 to bac6824 Compare January 6, 2023 21:44
@AlgoStephenAkiki AlgoStephenAkiki deleted the 1328-remove-go-algoranddatatransactionslogic-dependency branch January 6, 2023 21:45
@winder winder restored the 1328-remove-go-algoranddatatransactionslogic-dependency branch January 6, 2023 21:47
@winder winder reopened this Jan 6, 2023
@winder winder deleted the 1328-remove-go-algoranddatatransactionslogic-dependency branch August 3, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove go-algorand/data/transactions/logic dependency.
9 participants