-
Notifications
You must be signed in to change notification settings - Fork 838
P-chain - Multidimensional Static Fees #2703
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
Changes from all commits
95df851
74f0c18
9eda7f3
71b5930
0c0022e
f498af9
fc8afd8
3afc8e4
40031d0
52c94da
8bbc897
50c2ab9
6ae1419
0be756e
126fdc2
014a5ff
572aed5
78176ad
5761976
1861ce4
5c236e3
22f69c0
c285909
d75b029
e1144d5
dcc3b06
25b99e4
c025a6e
bb0cbe2
d505154
818c781
231ff5e
16fdab7
7f11841
f5ff8d6
26a9e31
8b06089
7f594ea
89da2ba
e26bec9
dd17dbb
0904787
2087443
2ef66ea
0cd2d7e
95d64cc
131c198
979e30d
566b09b
1b22091
f7d288c
fa0eb5a
4405a2e
480fb45
30498e7
1881282
fca9d28
0f24a1a
ba8e792
174b551
78bf907
d2d6aec
5aa5932
20a7c41
3b6b5f5
655e402
35fc006
035b35a
32ce3e0
ebc1b50
065ba42
952ed47
c050a42
a71fba1
2aa4b70
4b47e03
50e818f
4aedae5
a92b693
e418d7e
f1e5a44
0d5a1af
04c0b36
08def6a
e9860dc
c6cedd2
b01a2d2
eb59fda
5792e89
2661016
153e0ea
a56a753
2039a84
5569e4d
4c5787e
a581616
3e74610
9ac3a33
2c3f2a5
46e3895
5ad8365
16cf7c4
51729d9
6772d28
9481ff7
ade5178
ba48394
c6f7143
6de663b
6c9004d
318be91
41f1405
edbfd16
bc5b5e0
264706d
b2d11ce
ff6f721
5b6e9d8
7b9a26c
de272e6
09be1c4
b4f5329
711733e
b896652
4b9987a
320bc2d
7295437
26e8392
f0d573f
ac35175
4b6804b
cb1fefe
0e536e9
804c04f
5d3fce9
8e83a99
5719eae
9ad5ed4
feb8f93
cad0650
fdf25b2
270ce3e
98c7784
47cefa1
bf36767
f54eb12
f3b4936
f4d3bef
e8c33b8
3c85eb4
6ff6418
ebd5d11
bd31d35
d1ad5fa
703c58c
91a6e49
36d3c3c
a979da3
a1d127d
d90ee0f
8e22671
0fd16cd
4043ffd
4aa7c3d
09c615f
6413178
9f9c520
afe83b1
373a953
8981e5a
6379288
a95b53e
3aaa4be
7c05c64
beef890
e966579
6e7c9d5
0b3e3f7
c21f726
6d2003d
6e03a16
fe206db
5f224f9
1a317a3
b768c7a
04e18ba
6b3b23e
520a942
4cf3cce
65f00e9
2cd621a
520ef72
acddf41
7d82af2
366b46c
7dc8900
227b677
f31f1ac
69e46c6
c398294
b0edb2a
4b04fbb
48f5e5a
ec918b3
bb4c591
36b424f
931561e
4f71f0c
963bc8d
6f619a9
f505830
eb11869
0840496
f2b2d5e
a2edef0
b26f87c
45a5752
99e9574
1548cff
6f61cc3
30379a3
5500b2e
6cbe7c4
3f2862b
58c1c07
48de2c1
5c97117
0bf1e4f
531b21f
3fa3168
08e17ca
839a285
df43eb2
38a6b92
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ package executor | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "math/rand" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -36,6 +37,7 @@ import ( | |
| "github.com/ava-labs/avalanchego/utils/logging" | ||
| "github.com/ava-labs/avalanchego/utils/timer/mockable" | ||
| "github.com/ava-labs/avalanchego/utils/units" | ||
| "github.com/ava-labs/avalanchego/vms/components/avax" | ||
| "github.com/ava-labs/avalanchego/vms/platformvm/api" | ||
| "github.com/ava-labs/avalanchego/vms/platformvm/config" | ||
| "github.com/ava-labs/avalanchego/vms/platformvm/fx" | ||
|
|
@@ -61,15 +63,14 @@ const ( | |
| pending stakerStatus = iota | ||
| current | ||
|
|
||
| defaultWeight = 10000 | ||
| trackChecksum = false | ||
|
|
||
| apricotPhase3 fork = iota | ||
| apricotPhase5 | ||
| banff | ||
| cortina | ||
| durango | ||
| eUpgrade | ||
|
|
||
| latestFork = eUpgrade | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -78,17 +79,24 @@ var ( | |
| defaultGenesisTime = time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC) | ||
| defaultValidateStartTime = defaultGenesisTime | ||
| defaultValidateEndTime = defaultValidateStartTime.Add(10 * defaultMinStakingDuration) | ||
| defaultMinValidatorStake = 5 * units.MilliAvax | ||
| defaultBalance = 100 * defaultMinValidatorStake | ||
| preFundedKeys = secp256k1.TestKeys() | ||
| avaxAssetID = ids.ID{'y', 'e', 'e', 't'} | ||
| defaultTxFee = uint64(100) | ||
|
|
||
| defaultMinValidatorStake = 5 * units.MilliAvax | ||
| defaultMaxValidatorStake = 500 * units.MilliAvax | ||
| defaultMinDelegatorStake = 1 * units.MilliAvax | ||
| defaultBalance = 100 * defaultMinValidatorStake | ||
| defaultWeight = defaultBalance / 2 | ||
|
Contributor
Author
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. changes to unlock |
||
|
|
||
| preFundedKeys = secp256k1.TestKeys() | ||
| avaxAssetID = ids.ID{'y', 'e', 'e', 't'} | ||
| defaultTxFee = uint64(100) | ||
|
|
||
| genesisBlkID ids.ID | ||
| testSubnet1 *txs.Tx | ||
|
|
||
| // Node IDs of genesis validators. Initialized in init function | ||
| genesisNodeIDs []ids.NodeID | ||
|
|
||
| fundedSharedMemoryCalls byte | ||
|
Contributor
Author
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. copied from |
||
| ) | ||
|
|
||
| func init() { | ||
|
|
@@ -102,6 +110,10 @@ type stakerStatus uint | |
|
|
||
| type fork uint8 | ||
|
|
||
| type mutableSharedMemory struct { | ||
| atomic.SharedMemory | ||
| } | ||
|
|
||
| type staker struct { | ||
| nodeID ids.NodeID | ||
| rewardAddress ids.ShortID | ||
|
|
@@ -127,6 +139,7 @@ type environment struct { | |
| clk *mockable.Clock | ||
| baseDB *versiondb.Database | ||
| ctx *snow.Context | ||
| msm *mutableSharedMemory | ||
| fx fx.Fx | ||
| state state.State | ||
| mockedState *state.MockState | ||
|
|
@@ -152,6 +165,12 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller, f fork) *environment | |
| res.ctx.AVAXAssetID = avaxAssetID | ||
| res.ctx.SharedMemory = m.NewSharedMemory(res.ctx.ChainID) | ||
|
|
||
| msm := &mutableSharedMemory{ | ||
| SharedMemory: m.NewSharedMemory(res.ctx.ChainID), | ||
| } | ||
| res.ctx.SharedMemory = msm | ||
| res.msm = msm | ||
|
|
||
| res.fx = defaultFx(res.clk, res.ctx.Log, res.isBootstrapped.Get()) | ||
|
|
||
| rewardsCalc := reward.NewCalculator(res.config.RewardConfig) | ||
|
|
@@ -288,7 +307,7 @@ func addSubnet(env *environment) { | |
| if err != nil { | ||
| panic(err) | ||
| } | ||
| feeCalculator, err := state.PickFeeCalculator(env.config, stateDiff) | ||
| feeCalculator, err := state.PickFeeCalculator(env.config, stateDiff, stateDiff.GetTimestamp()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
@@ -354,9 +373,9 @@ func defaultConfig(t *testing.T, f fork) *config.Config { | |
| CreateSubnetTxFee: 100 * defaultTxFee, | ||
| CreateBlockchainTxFee: 100 * defaultTxFee, | ||
| }, | ||
| MinValidatorStake: 5 * units.MilliAvax, | ||
| MaxValidatorStake: 500 * units.MilliAvax, | ||
| MinDelegatorStake: 1 * units.MilliAvax, | ||
| MinValidatorStake: defaultMinValidatorStake, | ||
| MaxValidatorStake: defaultMaxValidatorStake, | ||
| MinDelegatorStake: defaultMinDelegatorStake, | ||
| MinStakeDuration: defaultMinStakingDuration, | ||
| MaxStakeDuration: defaultMaxStakingDuration, | ||
| RewardConfig: reward.Config{ | ||
|
|
@@ -557,3 +576,56 @@ func addPendingValidator( | |
| } | ||
| return addPendingValidatorTx, nil | ||
| } | ||
|
|
||
| // Returns a shared memory where GetDatabase returns a database | ||
| // where [recipientKey] has a balance of [amt] | ||
| func fundedSharedMemory( | ||
| t *testing.T, | ||
| env *environment, | ||
| sourceKey *secp256k1.PrivateKey, | ||
| peerChain ids.ID, | ||
| assets map[ids.ID]uint64, | ||
| ) atomic.SharedMemory { | ||
| fundedSharedMemoryCalls++ | ||
| m := atomic.NewMemory(prefixdb.New([]byte{fundedSharedMemoryCalls}, env.baseDB)) | ||
|
|
||
| sm := m.NewSharedMemory(env.ctx.ChainID) | ||
| peerSharedMemory := m.NewSharedMemory(peerChain) | ||
|
|
||
| for assetID, amt := range assets { | ||
| utxo := &avax.UTXO{ | ||
| UTXOID: avax.UTXOID{ | ||
| TxID: ids.GenerateTestID(), | ||
| OutputIndex: rand.Uint32(), // #nosec G404 | ||
| }, | ||
| Asset: avax.Asset{ID: assetID}, | ||
| Out: &secp256k1fx.TransferOutput{ | ||
| Amt: amt, | ||
| OutputOwners: secp256k1fx.OutputOwners{ | ||
| Locktime: 0, | ||
| Addrs: []ids.ShortID{sourceKey.PublicKey().Address()}, | ||
| Threshold: 1, | ||
| }, | ||
| }, | ||
| } | ||
| utxoBytes, err := txs.Codec.Marshal(txs.CodecVersion, utxo) | ||
| require.NoError(t, err) | ||
|
|
||
| inputID := utxo.InputID() | ||
| require.NoError(t, peerSharedMemory.Apply(map[ids.ID]*atomic.Requests{ | ||
| env.ctx.ChainID: { | ||
| PutRequests: []*atomic.Element{ | ||
| { | ||
| Key: inputID[:], | ||
| Value: utxoBytes, | ||
| Traits: [][]byte{ | ||
| sourceKey.PublicKey().Address().Bytes(), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| })) | ||
| } | ||
|
|
||
| return sm | ||
| } | ||
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.
minor code duplication removal