Skip to content

Commit

Permalink
Add l2 gas
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Jan 13, 2025
1 parent 96bb8af commit 457d863
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 14 deletions.
10 changes: 6 additions & 4 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
},
Receipts: AdaptHash(commitments.ReceiptCommitment),
ProtocolVersion: header.ProtocolVersion,
GasPriceFri: AdaptUint128(header.L1GasPriceSTRK),
L1GasPriceFri: AdaptUint128(header.L1GasPriceSTRK),
Signatures: utils.Map(header.Signatures, AdaptSignature),
StateDiffCommitment: &gen.StateDiffCommitment{
StateDiffLength: stateDiffLength,
Root: AdaptHash(stateDiffCommitment),
},
GasPriceWei: AdaptUint128(header.L1GasPriceETH),
DataGasPriceFri: AdaptUint128(header.L1DataGasPrice.PriceInFri),
DataGasPriceWei: AdaptUint128(header.L1DataGasPrice.PriceInWei),
L1GasPriceWei: AdaptUint128(header.L1GasPriceETH),
L1DataGasPriceFri: AdaptUint128(header.L1DataGasPrice.PriceInFri),
L1DataGasPriceWei: AdaptUint128(header.L1DataGasPrice.PriceInWei),
L1DataAvailabilityMode: adaptL1DA(header.L1DAMode),
L2GasPriceFri: AdaptUint128(header.L2GasPriceSTRK.NilToZero()),
L2GasPriceWei: AdaptUint128(header.L2GasPriceETH.NilToZero()),
}
}

Expand Down
4 changes: 3 additions & 1 deletion adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
return nil
}

var l1Gas, l1DataGas, totalL1Gas *felt.Felt
var l1Gas, l2Gas, l1DataGas, totalL1Gas *felt.Felt
if da := er.DataAvailability; da != nil { // todo(kirill) check that it might be null
l1Gas = new(felt.Felt).SetUint64(da.L1Gas)
l2Gas = new(felt.Felt).SetUint64(da.L2Gas)
l1DataGas = new(felt.Felt).SetUint64(da.L1DataGas)
}
if tgs := er.TotalGasConsumed; tgs != nil {
Expand All @@ -129,6 +130,7 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
L1Gas: AdaptFelt(l1Gas),
L2Gas: AdaptFelt(l2Gas),
L1DataGas: AdaptFelt(l1DataGas),
TotalL1Gas: AdaptFelt(totalL1Gas),
}
Expand Down
5 changes: 3 additions & 2 deletions adapters/core2p2p/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func adaptResourceLimits(bounds core.ResourceBounds) *gen.ResourceLimits {

func adaptResourceBounds(rb map[core.Resource]core.ResourceBounds) *gen.ResourceBounds {
return &gen.ResourceBounds{
L1Gas: adaptResourceLimits(rb[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(rb[core.ResourceL2Gas]),
L1Gas: adaptResourceLimits(rb[core.ResourceL1Gas]),
L1DataGas: adaptResourceLimits(rb[core.ResourceL1DataGas]),
L2Gas: adaptResourceLimits(rb[core.ResourceL2Gas]),
}
}

Expand Down
17 changes: 10 additions & 7 deletions adapters/p2p2core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ func AdaptBlockHeader(h *gen.SignedBlockHeader, eventsBloom *bloom.BloomFilter)
Timestamp: h.Time,
ProtocolVersion: h.ProtocolVersion,
EventsBloom: eventsBloom,
L1GasPriceETH: AdaptUint128(h.GasPriceWei),
L2GasPriceETH: &felt.Zero, // TODO: Fix when we have l2 gas price
L1GasPriceETH: AdaptUint128(h.L1GasPriceWei),
L2GasPriceETH: AdaptUint128(h.L2GasPriceWei),
Signatures: utils.Map(h.Signatures, adaptSignature),
L1GasPriceSTRK: AdaptUint128(h.GasPriceFri),
L2GasPriceSTRK: &felt.Zero, // TODO: Fix when we have l2 gas price
L1GasPriceSTRK: AdaptUint128(h.L1GasPriceFri),
L2GasPriceSTRK: AdaptUint128(h.L2GasPriceFri),
L1DAMode: adaptDA(h.L1DataAvailabilityMode),
L1DataGasPrice: &core.GasPrice{
PriceInWei: AdaptUint128(h.DataGasPriceWei),
PriceInFri: AdaptUint128(h.DataGasPriceFri),
PriceInWei: AdaptUint128(h.L1DataGasPriceWei),
PriceInFri: AdaptUint128(h.L1DataGasPriceFri),
},
L2GasPrice: &core.GasPrice{
PriceInWei: AdaptUint128(h.L2GasPriceWei),
PriceInFri: AdaptUint128(h.L2GasPriceFri),
},
L2GasPrice: nil, // todo pass correct value once it's in the p2p spec
}
}

Expand Down
2 changes: 2 additions & 0 deletions adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ func adaptExecutionResources(er *gen.Receipt_ExecutionResources) *core.Execution
},
DataAvailability: &core.DataAvailability{
L1Gas: feltToUint64(er.L1Gas),
L2Gas: feltToUint64(er.L2Gas),
L1DataGas: feltToUint64(er.L1DataGas),
},
MemoryHoles: uint64(er.MemoryHoles),
Steps: uint64(er.Steps), // todo SPEC 32 -> 64 bytes
TotalGasConsumed: &core.GasConsumed{
L1Gas: feltToUint64(er.TotalL1Gas),
L2Gas: feltToUint64(er.L2Gas),
// total_l1_data_gas = l1_data_gas, because there's only one place that can generate l1_data_gas costs
L1DataGas: feltToUint64(er.L1DataGas),
},
Expand Down
1 change: 1 addition & 0 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func adaptGasConsumed(response *starknet.GasConsumed) *core.GasConsumed {
return &core.GasConsumed{
L1Gas: response.L1Gas,
L1DataGas: response.L1DataGas,
L2Gas: response.L2Gas,
}
}

Expand Down
1 change: 1 addition & 0 deletions core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type GasConsumed struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
}

type TransactionReceipt struct {
Expand Down
1 change: 1 addition & 0 deletions core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type ExecutionResources struct {
type DataAvailability struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
}

type BuiltinInstanceCounter struct {
Expand Down
2 changes: 2 additions & 0 deletions starknet/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ type ExecutionResources struct {
type DataAvailability struct {
L1Gas uint64 `json:"l1_gas"`
L1DataGas uint64 `json:"l1_data_gas"`
L2Gas uint64 `json:"l2_gas"`
}

type BuiltinInstanceCounter struct {
Expand All @@ -240,6 +241,7 @@ type BuiltinInstanceCounter struct {
type GasConsumed struct {
L1Gas uint64 `json:"l1_gas"`
L1DataGas uint64 `json:"l1_data_gas"`
L2Gas uint64 `json:"l2_gas"`
}

type TransactionReceipt struct {
Expand Down

0 comments on commit 457d863

Please sign in to comment.