-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC update - add l2 gas #2335
base: main
Are you sure you want to change the base?
RPC update - add l2 gas #2335
Changes from all commits
eb440ca
ed8bedb
22a1e71
4029bac
a21356b
a1a1349
e2dfa59
3792091
06b97b3
ad9a361
f658ce3
0607ec7
374599d
d53108a
79d4105
64fee22
4ee2e41
28934ca
0382104
dfa0789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
} | ||
} | ||
|
||
type FeeEstimate struct { | ||
type FeeEstimateV0_7 struct { | ||
GasConsumed *felt.Felt `json:"gas_consumed"` | ||
GasPrice *felt.Felt `json:"gas_price"` | ||
DataGasConsumed *felt.Felt `json:"data_gas_consumed"` | ||
|
@@ -37,10 +37,45 @@ | |
Unit *FeeUnit `json:"unit,omitempty"` | ||
} | ||
|
||
type FeeEstimate struct { | ||
L1GasConsumed *felt.Felt `json:"l1_gas_consumed,omitempty"` | ||
L1GasPrice *felt.Felt `json:"l1_gas_price,omitempty"` | ||
L2GasConsumed *felt.Felt `json:"l2_gas_consumed,omitempty"` | ||
L2GasPrice *felt.Felt `json:"l2_gas_price,omitempty"` | ||
L1DataGasConsumed *felt.Felt `json:"l1_data_gas_consumed,omitempty"` | ||
L1DataGasPrice *felt.Felt `json:"l1_data_gas_price,omitempty"` | ||
OverallFee *felt.Felt `json:"overall_fee"` | ||
Unit *FeeUnit `json:"unit,omitempty"` | ||
} | ||
|
||
/**************************************************** | ||
Estimate Fee Handlers | ||
*****************************************************/ | ||
|
||
func feeEstimateToV0_7(feeEstimate FeeEstimate) FeeEstimateV0_7 { | ||
return FeeEstimateV0_7{ | ||
GasConsumed: feeEstimate.L1GasConsumed, | ||
GasPrice: feeEstimate.L1GasPrice, | ||
DataGasConsumed: feeEstimate.L1DataGasConsumed, | ||
DataGasPrice: feeEstimate.L1DataGasPrice, | ||
OverallFee: feeEstimate.OverallFee, | ||
Unit: feeEstimate.Unit, | ||
} | ||
} | ||
|
||
func (h *Handler) EstimateFeeV0_7(broadcastedTxns []BroadcastedTransaction, | ||
simulationFlags []SimulationFlag, id BlockID, | ||
) ([]FeeEstimateV0_7, http.Header, *jsonrpc.Error) { | ||
result, httpHeader, err := h.simulateTransactions(id, broadcastedTxns, append(simulationFlags, SkipFeeChargeFlag), true) | ||
if err != nil { | ||
return nil, httpHeader, err | ||
} | ||
|
||
return utils.Map(result, func(tx SimulatedTransaction) FeeEstimateV0_7 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can pass function name (=pointer) like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, |
||
return feeEstimateToV0_7(tx.FeeEstimation) | ||
}), httpHeader, nil | ||
} | ||
|
||
func (h *Handler) EstimateFee(broadcastedTxns []BroadcastedTransaction, | ||
simulationFlags []SimulationFlag, id BlockID, | ||
) ([]FeeEstimate, http.Header, *jsonrpc.Error) { | ||
|
@@ -54,18 +89,27 @@ | |
}), httpHeader, nil | ||
} | ||
|
||
func (h *Handler) EstimateMessageFee(msg MsgFromL1, id BlockID) (*FeeEstimate, http.Header, *jsonrpc.Error) { //nolint:gocritic | ||
return h.estimateMessageFee(msg, id, h.EstimateFee) | ||
//nolint:gocritic | ||
func (h *Handler) EstimateMessageFeeV0_7(msg MsgFromL1, id BlockID) (*FeeEstimateV0_7, http.Header, *jsonrpc.Error) { | ||
estimate, header, err := estimateMessageFee(msg, id, h.EstimateFee) | ||
if err != nil { | ||
return nil, header, err | ||
} | ||
estimateV0_7 := feeEstimateToV0_7(*estimate) | ||
return &estimateV0_7, header, nil | ||
} | ||
|
||
//nolint:gocritic | ||
func (h *Handler) EstimateMessageFee(msg MsgFromL1, id BlockID) (*FeeEstimate, http.Header, *jsonrpc.Error) { | ||
return estimateMessageFee(msg, id, h.EstimateFee) | ||
} | ||
|
||
type estimateFeeHandler func(broadcastedTxns []BroadcastedTransaction, | ||
simulationFlags []SimulationFlag, id BlockID, | ||
) ([]FeeEstimate, http.Header, *jsonrpc.Error) | ||
|
||
//nolint:gocritic | ||
func (h *Handler) estimateMessageFee(msg MsgFromL1, id BlockID, f estimateFeeHandler) (*FeeEstimate, | ||
http.Header, *jsonrpc.Error, | ||
) { | ||
func estimateMessageFee(msg MsgFromL1, id BlockID, f estimateFeeHandler) (*FeeEstimate, http.Header, *jsonrpc.Error) { | ||
calldata := make([]*felt.Felt, 0, len(msg.Payload)+1) | ||
// The order of the calldata parameters matters. msg.From must be prepended. | ||
calldata = append(calldata, new(felt.Felt).SetBytes(msg.From.Bytes())) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package rpc | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/NethermindEth/juno/core/felt" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFeeEstimateToV0_7(t *testing.T) { | ||
t.Run("empty", func(t *testing.T) { | ||
assert.Equal(t, FeeEstimateV0_7{}, feeEstimateToV0_7(FeeEstimate{})) | ||
}) | ||
|
||
t.Run("full", func(t *testing.T) { | ||
gasConsumed := new(felt.Felt).SetUint64(1) | ||
gasPrice := new(felt.Felt).SetUint64(2) | ||
dataGasConsumed := new(felt.Felt).SetUint64(3) | ||
dataGasPrice := new(felt.Felt).SetUint64(4) | ||
overallFee := new(felt.Felt).SetUint64(5) | ||
unit := WEI | ||
assert.Equal( | ||
t, | ||
FeeEstimateV0_7{ | ||
GasConsumed: gasConsumed, | ||
GasPrice: gasPrice, | ||
DataGasConsumed: dataGasConsumed, | ||
DataGasPrice: dataGasPrice, | ||
OverallFee: overallFee, | ||
Unit: &unit, | ||
}, | ||
feeEstimateToV0_7(FeeEstimate{ | ||
L1GasConsumed: gasConsumed, | ||
L1GasPrice: gasPrice, | ||
L2GasConsumed: new(felt.Felt).SetUint64(6), | ||
L2GasPrice: new(felt.Felt).SetUint64(7), | ||
L1DataGasConsumed: dataGasConsumed, | ||
L1DataGasPrice: dataGasPrice, | ||
OverallFee: overallFee, | ||
Unit: &unit, | ||
})) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it's not as simple as that. When we encode structures into bytes encoder it stores field names alongside their values so if we rename it here we receive nil in these fields even if our db is up to date.
@IronGauntlets please confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be fixed with tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked on block №800:
@kirugan you are right