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 16, 2025
1 parent eb85b3d commit 38eed5c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 3 deletions.
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
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 38eed5c

Please sign in to comment.