Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream' into add-x-to-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
siljapetasch committed Jul 25, 2024
2 parents b8149d0 + 32f384d commit 4af7279
Show file tree
Hide file tree
Showing 26 changed files with 1,514 additions and 1,323 deletions.
353 changes: 179 additions & 174 deletions cmd/subnetcmd/create.go

Large diffs are not rendered by default.

57 changes: 0 additions & 57 deletions cmd/subnetcmd/create_test.go

This file was deleted.

16 changes: 8 additions & 8 deletions cmd/subnetcmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ func TestExportImportSubnet(t *testing.T) {

app.Setup(testDir, logging.NoLog{}, nil, prompts.NewPrompter(), &mockAppDownloader)
ux.NewUserLog(logging.NoLog{}, io.Discard)
genBytes, sc, err := vm.CreateEvmSubnetConfig(
genBytes, err := vm.LoadCustomGenesis(
app,
testSubnet,
"../../"+utils.SubnetEvmGenesisPath,
)
require.NoError(err)
sc, err := vm.CreateEvmSidecar(
app,
testSubnet,
vmVersion,
"Test",
false,
0,
"",
false,
false,
nil,
)
require.NoError(err)
err = app.WriteGenesisFile(testSubnet, genBytes)
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestExportImportSubnet(t *testing.T) {
require.Equal(control["VMVersion"], vmVersion)
require.Equal(control["Subnet"], testSubnet)
require.Equal(control["TokenName"], "Test Token")
require.Equal(control["TokenSymbol"], "TEST")
require.Equal(control["TokenSymbol"], "Test")
require.Equal(control["Version"], constants.SidecarVersion)
require.Equal(control["Networks"], nil)

Expand Down
17 changes: 6 additions & 11 deletions cmd/subnetcmd/import_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (
importPublicSupportedNetworkOptions = []networkoptions.NetworkOption{networkoptions.Fuji, networkoptions.Mainnet}
blockchainIDstr string
nodeURL string
useSubnetEvm bool
useCustomVM bool
)

// avalanche subnet import public
Expand All @@ -45,7 +47,7 @@ flag.`,
cmd.Flags().StringVar(&nodeURL, "node-url", "", "[optional] URL of an already running subnet validator")

cmd.Flags().BoolVar(&useSubnetEvm, "evm", false, "import a subnet-evm")
cmd.Flags().BoolVar(&useCustom, "custom", false, "use a custom VM template")
cmd.Flags().BoolVar(&useCustomVM, "custom", false, "use a custom VM template")
cmd.Flags().BoolVar(
&overwriteImport,
"force",
Expand Down Expand Up @@ -133,16 +135,9 @@ func importPublic(*cobra.Command, []string) error {
// TODO: it's probably possible to deploy VMs with the same name on a public network
// In this case, an import could clash because the tool supports unique names only

vmType := getVMFromFlag()
if vmType == "" {
subnetTypeStr, err := app.Prompt.CaptureList(
"What's this VM's type?",
[]string{models.SubnetEvm, models.CustomVM},
)
if err != nil {
return err
}
vmType = models.VMTypeFromString(subnetTypeStr)
vmType, err := vm.PromptVMType(app, useSubnetEvm, useCustomVM)
if err != nil {
return err
}

vmIDstr := vmID.String()
Expand Down
190 changes: 174 additions & 16 deletions cmd/subnetcmd/upgradecmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const (
enabledLabel = "enabled"
managerLabel = "manager"
adminLabel = "admin"

NativeMint = "Native Minting"
ContractAllowList = "Contract Deployment Allow List"
TxAllowList = "Transaction Allow List"
FeeManager = "Adjust Fee Settings Post Deploy"
RewardManager = "Customize Fees Distribution"
)

var subnetName string
Expand Down Expand Up @@ -92,11 +98,11 @@ func upgradeGenerateCmd(_ *cobra.Command, args []string) error {
}

allPreComps := []string{
vm.ContractAllowList,
vm.FeeManager,
vm.NativeMint,
vm.TxAllowList,
vm.RewardManager,
ContractAllowList,
FeeManager,
NativeMint,
TxAllowList,
RewardManager,
}

fmt.Println()
Expand Down Expand Up @@ -197,15 +203,15 @@ func promptParams(precomp string, precompiles *[]params.PrecompileUpgrade) (bool
return false, err
}
switch precomp {
case vm.ContractAllowList:
case ContractAllowList:
return promptContractAllowListParams(&sc, precompiles, date)
case vm.TxAllowList:
case TxAllowList:
return promptTxAllowListParams(&sc, precompiles, date)
case vm.NativeMint:
case NativeMint:
return promptNativeMintParams(&sc, precompiles, date)
case vm.FeeManager:
case FeeManager:
return promptFeeManagerParams(&sc, precompiles, date)
case vm.RewardManager:
case RewardManager:
return promptRewardManagerParams(&sc, precompiles, date)
default:
return false, fmt.Errorf("unexpected precompile identifier: %q", precomp)
Expand Down Expand Up @@ -277,7 +283,7 @@ func promptRewardManagerParams(
if cancelled || err != nil {
return cancelled, err
}
initialConfig, err := vm.ConfigureInitialRewardConfig(app)
initialConfig, err := ConfigureInitialRewardConfig()
if err != nil {
return false, err
}
Expand All @@ -295,6 +301,42 @@ func promptRewardManagerParams(
return false, nil
}

func ConfigureInitialRewardConfig() (*rewardmanager.InitialRewardConfig, error) {
config := &rewardmanager.InitialRewardConfig{}

burnFees := "I am fine with transaction fees being burned
(Reward Manager Precompile OFF)"
distributeFees := "I want to customize the transaction fee distribution
(Reward Manager Precompile ON)"
options := []string{burnFees, distributeFees}
option, err := app.Prompt.CaptureList(
"By default, all transaction fees on Avalanche are burned (sent to a blackhole address). (Reward Manager Precompile)",
options,
)
if err != nil {
return config, err
}
if option == burnFees {
return config, nil
}

feeRcpdPrompt := "Allow block producers to claim fees?"
allowFeeRecipients, err := app.Prompt.CaptureYesNo(feeRcpdPrompt)
if err != nil {
return config, err
}
if allowFeeRecipients {
config.AllowFeeRecipients = true
return config, nil
}

rewardPrompt := "Provide the address to which fees will be sent to"
rewardAddress, err := app.Prompt.CaptureAddress(rewardPrompt)
if err != nil {
return config, err
}
config.RewardAddress = rewardAddress
return config, nil
}

func promptFeeManagerParams(
sc *models.Sidecar,
precompiles *[]params.PrecompileUpgrade,
Expand All @@ -311,7 +353,7 @@ func promptFeeManagerParams(
}
var feeConfig *commontype.FeeConfig
if yes {
chainConfig, _, err := vm.GetFeeConfig(params.ChainConfig{}, app, false)
chainConfig, err := GetFeeConfig(params.ChainConfig{}, false)
if err != nil {
return false, err
}
Expand All @@ -331,6 +373,122 @@ func promptFeeManagerParams(
return false, nil
}

func GetFeeConfig(config params.ChainConfig, useDefault bool) (
params.ChainConfig,
error,
) {
const (
lowOption = "Low block size / Low Throughput 12 mil gas per block"
mediumOption = "Medium block size / Medium Throughput 15 mil gas per block (C-Chain's setting)"
highOption = "High block size / High Throughput 20 mil gas per block"
customFee = "Customize fee config"

setGasLimit = "Set gas limit"
setBlockRate = "Set target block rate"
setMinBaseFee = "Set min base fee"
setTargetGas = "Set target gas"
setBaseFeeChangeDenominator = "Set base fee change denominator"
setMinBlockGas = "Set min block gas cost"
setMaxBlockGas = "Set max block gas cost"
setGasStep = "Set block gas cost step"
)

config.FeeConfig = vm.StarterFeeConfig

if useDefault {
config.FeeConfig.GasLimit = vm.LowGasLimit
config.FeeConfig.TargetGas = config.FeeConfig.TargetGas.Mul(config.FeeConfig.GasLimit, vm.NoDynamicFeesGasLimitToTargetGasFactor)
return config, nil
}

feeConfigOptions := []string{lowOption, mediumOption, highOption, customFee}

feeDefault, err := app.Prompt.CaptureList(
"How would you like to set fees",
feeConfigOptions,
)
if err != nil {
return config, err
}

useDynamicFees := false
if feeDefault != customFee {
useDynamicFees, err = app.Prompt.CaptureYesNo("Do you want to enable dynamic fees?")
if err != nil {
return config, err
}
}

switch feeDefault {
case lowOption:
vm.SetStandardGas(&config, vm.LowGasLimit, vm.LowTargetGas, useDynamicFees)
return config, nil
case mediumOption:
vm.SetStandardGas(&config, vm.MediumGasLimit, vm.MediumTargetGas, useDynamicFees)
return config, err
case highOption:
vm.SetStandardGas(&config, vm.HighGasLimit, vm.HighTargetGas, useDynamicFees)
return config, err
default:
ux.Logger.PrintToUser("Customizing fee config")
}

gasLimit, err := app.Prompt.CapturePositiveBigInt(setGasLimit)
if err != nil {
return config, err
}

blockRate, err := app.Prompt.CapturePositiveBigInt(setBlockRate)
if err != nil {
return config, err
}

minBaseFee, err := app.Prompt.CapturePositiveBigInt(setMinBaseFee)
if err != nil {
return config, err
}

targetGas, err := app.Prompt.CapturePositiveBigInt(setTargetGas)
if err != nil {
return config, err
}

baseDenominator, err := app.Prompt.CapturePositiveBigInt(setBaseFeeChangeDenominator)
if err != nil {
return config, err
}

minBlockGas, err := app.Prompt.CapturePositiveBigInt(setMinBlockGas)
if err != nil {
return config, err
}

maxBlockGas, err := app.Prompt.CapturePositiveBigInt(setMaxBlockGas)
if err != nil {
return config, err
}

gasStep, err := app.Prompt.CapturePositiveBigInt(setGasStep)
if err != nil {
return config, err
}

feeConf := commontype.FeeConfig{
GasLimit: gasLimit,
TargetBlockRate: blockRate.Uint64(),
MinBaseFee: minBaseFee,
TargetGas: targetGas,
BaseFeeChangeDenominator: baseDenominator,
MinBlockGasCost: minBlockGas,
MaxBlockGasCost: maxBlockGas,
BlockGasCostStep: gasStep,
}

config.FeeConfig = feeConf

return config, nil
}

func promptContractAllowListParams(
sc *models.Sidecar,
precompiles *[]params.PrecompileUpgrade,
Expand Down Expand Up @@ -444,15 +602,15 @@ func promptAdminManagerAndEnabledAddresses(
sc *models.Sidecar,
action string,
) ([]common.Address, []common.Address, []common.Address, bool, error) {
admin, manager, enabled, cancelled, err := vm.GenerateAllowList(app, action, sc.VMVersion)
allowList, cancelled, err := vm.GenerateAllowList(app, action, sc.VMVersion)
if cancelled || err != nil {
return nil, nil, nil, cancelled, err
}
if err := ensureHaveBalance(sc, adminLabel, admin); err != nil {
if err := ensureHaveBalance(sc, adminLabel, allowList.AdminAddresses); err != nil {
return nil, nil, nil, false, err
}
if err := ensureHaveBalance(sc, managerLabel, admin); err != nil {
if err := ensureHaveBalance(sc, managerLabel, allowList.ManagerAddresses); err != nil {
return nil, nil, nil, false, err
}
return admin, manager, enabled, false, nil
return allowList.AdminAddresses, allowList.ManagerAddresses, allowList.EnabledAddresses, false, nil
}
Loading

0 comments on commit 4af7279

Please sign in to comment.