Skip to content

Commit

Permalink
Fix fee estimation in simulateTransactions, fix DataAvailability pric…
Browse files Browse the repository at this point in the history
…es in traces (#1745)
  • Loading branch information
kirugan authored Mar 14, 2024
1 parent bf96204 commit 6317b0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
11 changes: 3 additions & 8 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1664,10 +1664,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
if !v0_6Response {
trace := traces[i]
executionResources := trace.TotalExecutionResources()
executionResources.DataAvailability = &vm.DataAvailability{
L1Gas: gasConsumed.Uint64(),
L1DataGas: dataGasConsumed[i].Uint64(),
}
executionResources.DataAvailability = vm.NewDataAvailability(gasConsumed, dataGasConsumed[i], header.L1DAMode)
traces[i].ExecutionResources = executionResources
}

Expand Down Expand Up @@ -1819,10 +1816,8 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
gasConsumed = gasConsumed.Div(gasConsumed, gasPrice) // division by zero felt is zero felt

executionResources := trace.TotalExecutionResources()
executionResources.DataAvailability = &vm.DataAvailability{
L1Gas: gasConsumed.Uint64(),
L1DataGas: dataGasConsumed[index].Uint64(),
}
executionResources.DataAvailability = vm.NewDataAvailability(gasConsumed, dataGasConsumed[index],
header.L1DAMode)
traces[index].ExecutionResources = executionResources
}
result = append(result, TracedBlockTransaction{
Expand Down
2 changes: 1 addition & 1 deletion vm/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub extern "C" fn cairoVMExecute(
}

// we are estimating fee, override actual fee calculation
if !charge_fee {
if t.actual_fee.0 == 0 {
t.actual_fee = calculate_tx_fee(&t.actual_resources, &block_context, &fee_type).unwrap();
}

Expand Down
14 changes: 14 additions & 0 deletions vm/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"slices"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
)

Expand Down Expand Up @@ -242,3 +243,16 @@ type ExecutionResources struct {
ComputationResources
DataAvailability *DataAvailability `json:"data_availability,omitempty"`
}

func NewDataAvailability(gasConsumed, dataGasConsumed *felt.Felt, mode core.L1DAMode) *DataAvailability {
da := &DataAvailability{}

switch mode {
case core.Calldata:
da.L1Gas = gasConsumed.Uint64()
case core.Blob:
da.L1DataGas = dataGasConsumed.Uint64()
}

return da
}

0 comments on commit 6317b0d

Please sign in to comment.