Skip to content

Commit 5c18415

Browse files
committed
feat: Check transaction size
1 parent 8d13b86 commit 5c18415

File tree

8 files changed

+30
-46
lines changed

8 files changed

+30
-46
lines changed

packages/chain/chain.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ type ChainCore interface {
9898
LatestAnchor(freshness StateFreshness) (*isc.StateAnchor, error)
9999
LatestState(freshness StateFreshness) (state.State, error)
100100
LatestGasCoin(freshness StateFreshness) (*coin.CoinWithRef, error)
101-
LatestL1Parameters() *parameters.L1Params
102101
GetCommitteeInfo() *CommitteeInfo // TODO: Review, maybe we can reorganize the CommitteeInfo structure.
103102
Store() indexedstore.IndexedStore // Use LatestState whenever possible. That will work faster.
104103
Processors() *processors.Config

packages/chain/cons/cons_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ func testConsBasic(t *testing.T, n, f int) {
190190
tc.WithInput(nid, cons.NewInputMempoolProposal(reqRefs))
191191
tc.WithInput(nid, cons.NewInputStateMgrProposalConfirmed())
192192
tc.WithInput(nid, cons.NewInputTimeData(now))
193-
<<<<<<< HEAD
194193
tc.WithInput(nid, cons.NewInputL1Info([]*coin.CoinWithRef{&gasCoin}, parameters.L1Default))
195-
=======
196-
tc.WithInput(nid, cons.NewInputGasInfo([]*coin.CoinWithRef{&gasCoin}, parameters.L1Default))
197-
>>>>>>> 3dc40ada6 (refactor: Pass L1parameter to consensus)
198194
}
199195
tc.RunAll()
200196
tc.PrintAllStatusStrings("After MP/SM proposals", t.Logf)

packages/chain/cons/input_gas_info.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/chain/cons/sync_nc.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ func (sync *syncNCImpl) tryCompleteInputs() gpa.OutMessages {
9191
return cb(sync.haveInputAnchor)
9292
}
9393

94-
<<<<<<< HEAD
9594
func (sync *syncNCImpl) HaveL1Info(gasCoins []*coin.CoinWithRef, l1params *parameters.L1Params) gpa.OutMessages {
96-
=======
97-
func (sync *syncNCImpl) HaveGasInfo(gasCoins []*coin.CoinWithRef, l1params *parameters.L1Params) gpa.OutMessages {
98-
>>>>>>> 3dc40ada6 (refactor: Pass L1parameter to consensus)
9995
if sync.gasCoins == nil && gasCoins != nil {
10096
sync.gasCoins = gasCoins
10197
}

packages/chain/node.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import (
4646
"github.com/iotaledger/wasp/packages/isc"
4747
"github.com/iotaledger/wasp/packages/metrics"
4848
"github.com/iotaledger/wasp/packages/origin"
49-
"github.com/iotaledger/wasp/packages/parameters"
5049
"github.com/iotaledger/wasp/packages/peering"
5150
"github.com/iotaledger/wasp/packages/registry"
5251
"github.com/iotaledger/wasp/packages/shutdown"
@@ -1076,10 +1075,6 @@ func (cni *chainNodeImpl) LatestGasCoin(freshness StateFreshness) (*coin.CoinWit
10761075
return cni.nodeConn.GetGasCoinRef(context.Background(), cni.chainID)
10771076
}
10781077

1079-
func (cni *chainNodeImpl) LatestL1Parameters() *parameters.L1Params {
1080-
return parameters.L1()
1081-
}
1082-
10831078
func (cni *chainNodeImpl) LatestState(freshness StateFreshness) (state.State, error) {
10841079
cni.accessLock.RLock()
10851080
latestActiveState := cni.latestActiveState

packages/vm/vmimpl/runreq.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package vmimpl
22

33
import (
4+
"fmt"
45
"math"
56
"math/big"
67
"os"
78
"runtime/debug"
89
"time"
910

11+
"github.com/iotaledger/wasp/clients/iota-go/iotago"
12+
"github.com/iotaledger/wasp/clients/iota-go/iotago/iotatest"
1013
"github.com/iotaledger/wasp/packages/coin"
1114
"github.com/iotaledger/wasp/packages/hashing"
1215
"github.com/iotaledger/wasp/packages/isc"
@@ -16,6 +19,7 @@ import (
1619
"github.com/iotaledger/wasp/packages/kv/codec"
1720
"github.com/iotaledger/wasp/packages/parameters"
1821
"github.com/iotaledger/wasp/packages/util"
22+
"github.com/iotaledger/wasp/packages/util/bcs"
1923
"github.com/iotaledger/wasp/packages/util/panicutil"
2024
"github.com/iotaledger/wasp/packages/vm"
2125
"github.com/iotaledger/wasp/packages/vm/core/accounts"
@@ -57,7 +61,7 @@ func (vmctx *vmContext) runRequest(req isc.Request, requestIndex uint16, mainten
5761

5862
result, err := reqctx.callTheContract()
5963
if err == nil {
60-
err = vmctx.checkTransactionSize() // TODO is this a concern now?
64+
err = vmctx.checkTransactionSize()
6165
}
6266
if err != nil {
6367
// skip the request / rollback tx builder (no need to rollback the state, because the mutations will never be applied)
@@ -476,11 +480,23 @@ func (vmctx *vmContext) loadChainConfig() {
476480

477481
// checkTransactionSize panics with ErrMaxTransactionSizeExceeded if the estimated transaction size exceeds the limit
478482
func (vmctx *vmContext) checkTransactionSize() error {
479-
// TODO the following requirements we need to check
480-
// * The encoded bytes of ptb should be smaller than `max_tx_size_bytes`
481-
// * max_size_written_objects
482-
// * max_serialized_tx_effects_size_bytes
483-
// * max_pure_argument_size
484-
vmctx.task.Log.Info("TODO: checkTransactionSize")
483+
const maxTxSizeBytes = 128 * 1024
484+
const maxInputObjects = 2048
485+
const maxProgrammableTxCommands = 1024
486+
ptb := vmctx.txbuilder.ViewPTB()
487+
if ptb.Inputs.Len() > maxInputObjects {
488+
return fmt.Errorf("ptb input len: %d, exceed max_input_objects", ptb.Inputs.Len())
489+
}
490+
if len(ptb.Commands) > maxProgrammableTxCommands {
491+
return fmt.Errorf("ptb input len: %d, exceed max_programmable_tx_commands", len(ptb.Commands))
492+
}
493+
pt := ptb.Finish()
494+
tx := iotago.NewProgrammable(
495+
iotatest.RandomAddress(), pt, []*iotago.ObjectRef{iotatest.RandomObjectRef()}, 0, 0,
496+
)
497+
b, _ := bcs.Marshal(&tx)
498+
if len(b) > maxTxSizeBytes {
499+
return fmt.Errorf("ptb serialized size: %d, exceed max_tx_size_bytes", maxTxSizeBytes)
500+
}
485501
return nil
486502
}

packages/vm/vmtxbuilder/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ type TransactionBuilder interface {
2020

2121
// this will reset txb into nil
2222
BuildTransactionEssence(stateMetadata []byte, topUpAmount uint64) iotago.ProgrammableTransaction
23+
24+
// return a clone of PTB object for viewing
25+
ViewPTB() *iotago.ProgrammableTransactionBuilder
2326
}

packages/vm/vmtxbuilder/txbuilder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,7 @@ func (txb *AnchorTransactionBuilder) BuildTransactionEssence(stateMetadata []byt
139139
}
140140
return ptb.Finish()
141141
}
142+
143+
func (txb *AnchorTransactionBuilder) ViewPTB() *iotago.ProgrammableTransactionBuilder {
144+
return txb.ptb.Clone()
145+
}

0 commit comments

Comments
 (0)