-
Notifications
You must be signed in to change notification settings - Fork 87
Allow ParamUpdater to update PoS consensus params #499
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
Merged
lazynina
merged 11 commits into
feature/proof-of-stake
from
mf/param-updater-update-pos-global-params
Jun 13, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6e8b05b
Allow ParamUpdater to update PoS GlobalParams.
mattfoley8 1a5fc70
Add epoch number to get pos params call.
mattfoley8 589aaae
Merge branch 'feature/pos-txn-types' into mf/param-updater-update-pos…
mattfoley8 e827b09
Merge branch 'feature/pos-txn-types' into mf/param-updater-update-pos…
mattfoley8 a446335
Merge branch 'main' into mf/param-updater-update-pos-global-params
mattfoley8 8c49e1c
Change core branch in test Dockerfile.
mattfoley8 ff79a2a
Add test for updating global params.
mattfoley8 f190c9a
Fix bugs in testing updating global params.
mattfoley8 d28af2b
Checkout correct core branch.
mattfoley8 cbdb9ec
Merge branch 'feature/proof-of-stake' into mf/param-updater-update-po…
mattfoley8 d37b59d
Change core branch.
mattfoley8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package routes | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "github.com/deso-protocol/core/lib" | ||
| "github.com/stretchr/testify/require" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestUpdateGlobalParams(t *testing.T) { | ||
| // Hard-coded test constants | ||
| adminPublicKeyBase58Check := "tBCKWVydPvhXyxSVhntXCw7wUev2fUx64h84FLAfz4JStsdBAq4v9r" | ||
| adminJWT := "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDQ3MDU1Mzh9.LXA2uT8tm-6DXDwTXaCRyqqbFNa96jLl_02LXyAwq58PbVPe28hrICP3P-D5g9mktPJolSVXK_UebRcL5oYCWg" | ||
|
|
||
| // Init api server | ||
| apiServer := newTestApiServer(t) | ||
| apiServer.Config.SuperAdminPublicKeys = []string{adminPublicKeyBase58Check} | ||
| senderPkBytes, _, err := lib.Base58CheckDecode(senderPkString) | ||
| require.NoError(t, err) | ||
| apiServer.Params.ExtraRegtestParamUpdaterKeys[lib.MakePkMapKey(senderPkBytes)] = true | ||
|
|
||
| // Helper utils | ||
| getGlobalParams := func() *GetGlobalParamsResponse { | ||
| // Send POST request. | ||
| body := GetGlobalParamsRequest{} | ||
| bodyJSON, err := json.Marshal(body) | ||
| require.NoError(t, err) | ||
| request, _ := http.NewRequest("POST", RoutePathGetGlobalParams, bytes.NewBuffer(bodyJSON)) | ||
| request.Header.Set("Content-Type", "application/json") | ||
| response := httptest.NewRecorder() | ||
| apiServer.router.ServeHTTP(response, request) | ||
| require.NotContains(t, string(response.Body.Bytes()), "error") | ||
|
|
||
| // Decode response. | ||
| decoder := json.NewDecoder(io.LimitReader(response.Body, MaxRequestBodySizeBytes)) | ||
| globalParams := GetGlobalParamsResponse{} | ||
| err = decoder.Decode(&globalParams) | ||
| return &globalParams | ||
| } | ||
|
|
||
| updateGlobalParams := func(body *UpdateGlobalParamsRequest) { | ||
| // Add JWT auth to body of request. | ||
| type MergedBody struct { | ||
| AdminRequest | ||
| UpdateGlobalParamsRequest | ||
| } | ||
| mergedBody := MergedBody{ | ||
| AdminRequest: AdminRequest{ | ||
| JWT: adminJWT, AdminPublicKey: adminPublicKeyBase58Check, | ||
| }, | ||
| UpdateGlobalParamsRequest: *body, | ||
| } | ||
|
|
||
| // Send POST request. | ||
| bodyJSON, err := json.Marshal(mergedBody) | ||
| require.NoError(t, err) | ||
| request, _ := http.NewRequest("POST", RoutePathUpdateGlobalParams, bytes.NewBuffer(bodyJSON)) | ||
| request.Header.Set("Content-Type", "application/json") | ||
| response := httptest.NewRecorder() | ||
| apiServer.router.ServeHTTP(response, request) | ||
| require.NotContains(t, string(response.Body.Bytes()), "error") | ||
|
|
||
| // Decode response. | ||
| decoder := json.NewDecoder(io.LimitReader(response.Body, MaxRequestBodySizeBytes)) | ||
| updateGlobalParamsResponse := UpdateGlobalParamsResponse{} | ||
| err = decoder.Decode(&updateGlobalParamsResponse) | ||
| require.NoError(t, err) | ||
| txn := updateGlobalParamsResponse.Transaction | ||
|
|
||
| // Sign txn. | ||
| require.Nil(t, txn.Signature.Sign) | ||
| signTxn(t, txn, senderPrivString) | ||
| require.NotNil(t, txn.Signature.Sign) | ||
|
|
||
| // Submit txn. | ||
| _, err = submitTxn(t, apiServer, txn) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| // Tests | ||
| { | ||
| // Confirm default GlobalParams. | ||
| globalParams := getGlobalParams() | ||
| require.Zero(t, globalParams.MinimumNetworkFeeNanosPerKB) | ||
| require.Equal(t, globalParams.StakeLockupEpochDuration, uint64(3)) | ||
| require.Equal(t, globalParams.ValidatorJailEpochDuration, uint64(3)) | ||
| require.Equal(t, globalParams.LeaderScheduleMaxNumValidators, uint64(100)) | ||
| require.Equal(t, globalParams.EpochDurationNumBlocks, uint64(3600)) | ||
| require.Equal(t, globalParams.JailInactiveValidatorGracePeriodEpochs, uint64(48)) | ||
| } | ||
| { | ||
| // Update all GlobalParam fields. | ||
| updateGlobalParams(&UpdateGlobalParamsRequest{ | ||
| UpdaterPublicKeyBase58Check: senderPkString, | ||
| MinimumNetworkFeeNanosPerKB: 99, | ||
| StakeLockupEpochDuration: 4, | ||
| ValidatorJailEpochDuration: 4, | ||
| LeaderScheduleMaxNumValidators: 101, | ||
| EpochDurationNumBlocks: 3601, | ||
| JailInactiveValidatorGracePeriodEpochs: 49, | ||
| MinFeeRateNanosPerKB: 99, | ||
| }) | ||
| } | ||
| { | ||
| // Verify all updated GlobalParam fields. | ||
| globalParams := getGlobalParams() | ||
| require.Equal(t, globalParams.MinimumNetworkFeeNanosPerKB, uint64(99)) | ||
| require.Equal(t, globalParams.StakeLockupEpochDuration, uint64(4)) | ||
| require.Equal(t, globalParams.ValidatorJailEpochDuration, uint64(4)) | ||
| require.Equal(t, globalParams.LeaderScheduleMaxNumValidators, uint64(101)) | ||
| require.Equal(t, globalParams.EpochDurationNumBlocks, uint64(3601)) | ||
| require.Equal(t, globalParams.JailInactiveValidatorGracePeriodEpochs, uint64(49)) | ||
| } | ||
| { | ||
| // Update only one GlobalParam field. | ||
| updateGlobalParams(&UpdateGlobalParamsRequest{ | ||
| UpdaterPublicKeyBase58Check: senderPkString, | ||
| MinimumNetworkFeeNanosPerKB: 99, | ||
| JailInactiveValidatorGracePeriodEpochs: 50, | ||
| MinFeeRateNanosPerKB: 99, | ||
| }) | ||
| } | ||
| { | ||
| // Verify updated GlobalParam field. And other fields retain old values. | ||
| globalParams := getGlobalParams() | ||
| require.Equal(t, globalParams.MinimumNetworkFeeNanosPerKB, uint64(99)) | ||
| require.Equal(t, globalParams.StakeLockupEpochDuration, uint64(4)) | ||
| require.Equal(t, globalParams.ValidatorJailEpochDuration, uint64(4)) | ||
| require.Equal(t, globalParams.LeaderScheduleMaxNumValidators, uint64(101)) | ||
| require.Equal(t, globalParams.EpochDurationNumBlocks, uint64(3601)) | ||
| require.Equal(t, globalParams.JailInactiveValidatorGracePeriodEpochs, uint64(50)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we typically pass these params as -1 if we don't want to update them in case there's a situation when we'd want them to be 0. I don't think we'll ever want any of these values to be 0 though. Is that assumption correct? It's not a huge deal if we decide to change these later and also provides more safety - if we forget to specify these when making the request, they'll be zero and be left out. okay I've talked myself into it - these are correct.