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

soroban-rpc: preflight: remove key sizes from read_bytes computation #922

Merged
merged 5 commits into from
Sep 5, 2023

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Sep 4, 2023

Core stopped including including them

Followup from #913 (comment)

@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

This has unveiled yet another ResourceLimitExceeded error when running the BumpFootprint operation. The test fails at https://github.com/2opremio/soroban-cli/blob/remove-keys-from-fee-estimation/cmd/soroban-rpc/internal/test/simulate_transaction_test.go#L748

envelope: AAAAAgAAAABzdv3ojkzWHMD7KUoXhrPx0GH18vHKV0ZfqpMiEblG1gAAZqAAAAAAAAAABAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAGQAAAAAAAAAUAAAAAQAAAAAAAAABAAAABgAAAAFnrAIfzK644FciM7c4L1q7oxCN5UdDC/Y0lL2onFdNaAAAAA8AAAAHQ09VTlRFUgAAAAABAAAAAAAAAAAAAAB0AAAAAAAAAAAAAE5FAAAAARG5RtYAAABAGAKEmnKibE8ikaCWwDf34EbFh3OeWSWc4gnsF0RY8B8+xLuOsB/EgHjf1Ns1/r0WssqDrf3P8zO2H3V9k/8pAA==

The soroban transaction data is the following. My guess is that we are not accounting for the written expiration entries. I will try to fix that.
Screenshot 2023-09-04 at 19 01 00

@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

Unfortunately, adding the write bytes didn't make the test pass. Here is the new soroban transaction data:

Screenshot 2023-09-04 at 19 15 48

@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

Now, thinking about it, the write_bytes couldn't be the problem since they were already 0 before this PR. Something else is amiss.

@2opremio 2opremio force-pushed the remove-keys-from-fee-estimation branch from 60de49c to c38a1e5 Compare September 4, 2023 17:35
@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

If you set read_bytes to 128 the test passes but it fails if set to 127 so we are missing 128 - 116 = 12 bytes which I am not sure how to account for.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

The serialized length of an expiration ledger entry is 48, and not 36. This explains the missing 12 bytes :S

I noticed that fees.rs in rs-soroban-env also gets it wrong (@sisuresh I guess you copy-pased it from there) so it should be corrected.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 4, 2023

To be more specific. This prints 48:

	entry2 := xdr.LedgerEntry{
		LastModifiedLedgerSeq: 4,
		Data: xdr.LedgerEntryData{
			Type: xdr.LedgerEntryTypeExpiration,
			Expiration: &xdr.ExpirationEntry{
				KeyHash:             xdr.Hash{},
				ExpirationLedgerSeq: 0,
			},
		},
		Ext: xdr.LedgerEntryExt{},
	}
	bin, err := entry.MarshalBinary()
	assert.NoError(t, err)
	fmt.Println(len(bin))

whereas the Rust code reads

 /// Estimate for any `ExpirationEntry` ledger entry, consisting of a 32-byte
 /// hash of the corresponding entry and 4 bytes for expiration ledger.
const EXPIRATION_ENTRY_SIZE: u32 = 32 + 4;

The calculation above didn't take into account the ledger entry type nor the LastModifiedLedgerSeq field

@2opremio 2opremio force-pushed the remove-keys-from-fee-estimation branch from fcfe0e8 to 592d60d Compare September 4, 2023 23:38
@2opremio
Copy link
Contributor Author

2opremio commented Sep 5, 2023

This is ready to merge, but let's not do it until @sisuresh / @dmkozh confirm that the EXPIRATION_ENTRY_SIZE fix is correct.

@2opremio
Copy link
Contributor Author

2opremio commented Sep 5, 2023

We still need to update the sdk and soroban-env with the upstream fix once this merges

@2opremio 2opremio enabled auto-merge (squash) September 5, 2023 16:19
@2opremio 2opremio merged commit 954e6f7 into stellar:main Sep 5, 2023
18 of 19 checks passed
@2opremio 2opremio deleted the remove-keys-from-fee-estimation branch September 5, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants