Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix tx size check

* fix tx size check

* refactor

* fix test

* fix test

* fix
  • Loading branch information
ToniRamirezM authored Nov 20, 2023
1 parent ece1053 commit b7e59ae
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ func start(cliCtx *cli.Context) error {
currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId
log.Infof("Fork ID read from POE SC = %v", forkIDIntervals[len(forkIDIntervals)-1].ForkId)
c.Aggregator.ChainID = l2ChainID
log.Infof("Chain ID read from POE SC = %v", l2ChainID)
// If the aggregator is restarted before the end of the sync process, this currentForkID could be wrong
c.Aggregator.ForkId = currentForkID
log.Infof("Chain ID read from POE SC = %v", l2ChainID)
c.Pool.ForkID = currentForkID

ethTxManagerStorage, err := ethtxmanager.NewPostgresStorage(c.State.DB)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ MaxGasPriceLimit=0
| - [AccountQueue](#Pool_AccountQueue ) | No | integer | No | - | AccountQueue represents the maximum number of non-executable transaction slots permitted per account |
| - [GlobalQueue](#Pool_GlobalQueue ) | No | integer | No | - | GlobalQueue represents the maximum number of non-executable transaction slots for all accounts |
| - [EffectiveGasPrice](#Pool_EffectiveGasPrice ) | No | object | No | - | EffectiveGasPrice is the config for the effective gas price calculation |
| - [ForkID](#Pool_ForkID ) | No | integer | No | - | ForkID is the current fork ID of the chain |

### <a name="Pool_IntervalToRefreshBlockedAddresses"></a>7.1. `Pool.IntervalToRefreshBlockedAddresses`

Expand Down Expand Up @@ -827,6 +828,20 @@ BreakEvenFactor=1.1
FinalDeviationPct=10
```

### <a name="Pool_ForkID"></a>7.12. `Pool.ForkID`

**Type:** : `integer`

**Default:** `0`

**Description:** ForkID is the current fork ID of the chain

**Example setting the default value** (0):
```
[Pool]
ForkID=0
```

## <a name="RPC"></a>8. `[RPC]`

**Type:** : `object`
Expand Down
5 changes: 5 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@
"additionalProperties": false,
"type": "object",
"description": "EffectiveGasPrice is the config for the effective gas price calculation"
},
"ForkID": {
"type": "integer",
"description": "ForkID is the current fork ID of the chain",
"default": 0
}
},
"additionalProperties": false,
Expand Down
3 changes: 3 additions & 0 deletions pool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Config struct {

// EffectiveGasPrice is the config for the effective gas price calculation
EffectiveGasPrice EffectiveGasPriceCfg `mapstructure:"EffectiveGasPrice"`

// ForkID is the current fork ID of the chain
ForkID uint64 `mapstructure:"ForkID"`
}

// EffectiveGasPriceCfg contains the configuration properties for the effective gas price
Expand Down
7 changes: 6 additions & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ func (p *Pool) validateTx(ctx context.Context, poolTx Transaction) error {
}

// Reject transactions over defined size to prevent DOS attacks
if poolTx.Size() > p.cfg.MaxTxBytesSize {
decodedTx, err := state.EncodeTransaction(poolTx.Transaction, 0xFF, p.cfg.ForkID) //nolint: gomnd
if err != nil {
return ErrTxTypeNotSupported
}

if uint64(len(decodedTx)) > p.cfg.MaxTxBytesSize {
log.Infof("%v: %v", ErrOversizedData.Error(), from.String())
return ErrOversizedData
}
Expand Down
2 changes: 1 addition & 1 deletion sequencer/txtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*
GasPrice: tx.GasPrice(),
Cost: tx.Cost(),
BatchResources: state.BatchResources{
Bytes: tx.Size(),
Bytes: uint64(len(rawTx)) + state.EfficiencyPercentageByteLength,
ZKCounters: counters,
},
RawTx: rawTx,
Expand Down
22 changes: 12 additions & 10 deletions state/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ const (
// MaxEffectivePercentage is the maximum value that can be used as effective percentage
MaxEffectivePercentage = uint8(255)
// Decoding constants
headerByteLength uint64 = 1
sLength uint64 = 32
rLength uint64 = 32
vLength uint64 = 1
c0 uint64 = 192 // 192 is c0. This value is defined by the rlp protocol
ff uint64 = 255 // max value of rlp header
shortRlp uint64 = 55 // length of the short rlp codification
f7 uint64 = 247 // 192 + 55 = c0 + shortRlp
efficiencyPercentageByteLength uint64 = 1
headerByteLength uint64 = 1
sLength uint64 = 32
rLength uint64 = 32
vLength uint64 = 1
c0 uint64 = 192 // 192 is c0. This value is defined by the rlp protocol
ff uint64 = 255 // max value of rlp header
shortRlp uint64 = 55 // length of the short rlp codification
f7 uint64 = 247 // 192 + 55 = c0 + shortRlp

// EfficiencyPercentageByteLength is the length of the effective percentage in bytes
EfficiencyPercentageByteLength uint64 = 1
)

// EncodeTransactions RLP encodes the given transactions
Expand Down Expand Up @@ -205,7 +207,7 @@ func DecodeTxs(txsData []byte, forkID uint64) ([]types.Transaction, []byte, []ui
endPos := pos + length + rLength + sLength + vLength + headerByteLength

if forkID >= DRAGONFRUIT_FORKID {
endPos += efficiencyPercentageByteLength
endPos += EfficiencyPercentageByteLength
}

if endPos > txDataLength {
Expand Down

0 comments on commit b7e59ae

Please sign in to comment.