-
Notifications
You must be signed in to change notification settings - Fork 524
pool fees in a txgroup #2173
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
pool fees in a txgroup #2173
Changes from all commits
29e01a8
2a1bbc8
a6d80f7
23def11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,10 +108,6 @@ func Txn(s *transactions.SignedTxn, txnIdx int, groupCtx *GroupContext) error { | |
| return err | ||
| } | ||
|
|
||
| if s.Txn.Src().IsZero() { | ||
| return errors.New("empty address") | ||
| } | ||
|
|
||
| return stxnVerifyCore(s, txnIdx, groupCtx) | ||
| } | ||
|
|
||
|
|
@@ -121,13 +117,34 @@ func TxnGroup(stxs []transactions.SignedTxn, contextHdr bookkeeping.BlockHeader, | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| minFeeCount := uint64(0) | ||
| feesPaid := uint64(0) | ||
| for i, stxn := range stxs { | ||
| err = Txn(&stxn, i, groupCtx) | ||
| if err != nil { | ||
| err = fmt.Errorf("transaction %+v invalid : %w", stxn, err) | ||
| return | ||
| } | ||
| if stxn.Txn.Type != protocol.CompactCertTx { | ||
| minFeeCount++ | ||
| } | ||
| feesPaid = basics.AddSaturate(feesPaid, stxn.Txn.Fee.Raw) | ||
| } | ||
| feeNeeded, overflow := basics.OMul(groupCtx.consensusParams.MinTxnFee, minFeeCount) | ||
| if overflow { | ||
| err = fmt.Errorf("txgroup fee requirement overflow") | ||
| return | ||
| } | ||
| // feesPaid may have saturated. That's ok. Since we know | ||
| // feeNeeded did not overlfow, simple comparision tells us | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: overflow
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't make me face the wrath of CI again!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry.. but at least you know that it should be passing. |
||
| // feesPaid was enough. | ||
| if feesPaid < feeNeeded { | ||
| err = fmt.Errorf("txgroup had %d in fees, which is less than the minimum %d * %d", | ||
| feesPaid, minFeeCount, groupCtx.consensusParams.MinTxnFee) | ||
| return | ||
| } | ||
|
|
||
algorandskiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if cache != nil { | ||
| cache.Add(stxs, groupCtx) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,11 @@ func TestPaymentValidation(t *testing.T) { | |
| if badFee.WellFormed(spec, tc.Proto) == nil { | ||
| t.Errorf("transaction with no fee %#v verified incorrectly", badFee) | ||
| } | ||
| badFee.Fee.Raw = 1 | ||
| if badFee.WellFormed(spec, tc.Proto) == nil { | ||
| t.Errorf("transaction with low fee %#v verified incorrectly", badFee) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused what this checks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I think this unit test should have existed before. I wrote it while I was still feeling my way around, before I wrote any of this code. It will, in fact, never be triggered after the protocol upgrade that this code requires. But it does give me something to test against when writing the integration tests. I wanted to confirm that a low fee transaction was bad, but now is not. |
||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/bin/bash | ||
|
|
||
| filename=$(basename "$0") | ||
| scriptname="${filename%.*}" | ||
| date "+${scriptname} start %Y%m%d_%H%M%S" | ||
|
|
||
| set -e | ||
| set -x | ||
| set -o pipefail | ||
| export SHELLOPTS | ||
|
|
||
| WALLET=$1 | ||
|
|
||
| gcmd="goal -w ${WALLET}" | ||
|
|
||
| PAYER=$(${gcmd} account list|awk '{ print $3 }') | ||
| MOOCHER=$(${gcmd} account new|awk '{ print $6 }') | ||
|
|
||
| # Fund MOOCHER, 1M | ||
| ${gcmd} clerk send -a 1000000 -f "${PAYER}" -t "${MOOCHER}" | ||
|
|
||
| # Payer and Moocher are going to pay each other 100 mAlgos, but | ||
| # Moocher is not going to pay the minfee (Payer will pay double) | ||
|
|
||
| # Fair number of temporary files, just cd into TEMPDIR first | ||
| cd ${TEMPDIR} | ||
|
|
||
| # Check a low fee from moocher | ||
| ${gcmd} clerk send -a 100 -f "${MOOCHER}" -t "${PAYER}" --fee 2 -o cheap.txn | ||
| # Since goal was modified to allow < minfee when this feature was added, let's confirm | ||
| msgpacktool -d < cheap.txn | grep fee | grep 2 | ||
| ${gcmd} clerk send -a 100 -f "${PAYER}" -t "${MOOCHER}" --fee 2000 -o expensive.txn | ||
| cat cheap.txn expensive.txn > both.txn | ||
| ${gcmd} clerk group -i both.txn -o group.txn | ||
| ${gcmd} clerk sign -i group.txn -o group.stx | ||
| ${gcmd} clerk rawsend -f group.stx | ||
|
|
||
| # Check a zero fee from moocher | ||
| ${gcmd} clerk send -a 100 -f "${MOOCHER}" -t "${PAYER}" --fee 0 -o cheap.txn | ||
| # Since goal was modified to allow zero when this feature was added, let's confirm | ||
| # that it's not encoded (should be "omitempty") | ||
| set +e | ||
| FOUND=$(msgpacktool -d < cheap.txn | grep fee) | ||
| set -e | ||
| if [[ $FOUND != "" ]]; then | ||
| date "+{scriptname} FAIL fee was improperly encoded $FOUND %Y%m%d_%H%M%S" | ||
| false | ||
| fi | ||
|
|
||
| ${gcmd} clerk send -a 100 -f "${PAYER}" -t "${MOOCHER}" --fee 2000 -o expensive.txn | ||
| cat cheap.txn expensive.txn > both.txn | ||
| ${gcmd} clerk group -i both.txn -o group.txn | ||
| ${gcmd} clerk sign -i group.txn -o group.stx | ||
| ${gcmd} clerk rawsend -f group.stx | ||
|
|
||
|
|
||
| date "+${scriptname} OK %Y%m%d_%H%M%S" |
Uh oh!
There was an error while loading. Please reload this page.