From 476cbbebdcd82e96cd05039234a5ea19102d8e40 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 21 Jan 2021 23:02:59 +0300 Subject: [PATCH] native: make registering as a candidate cost more Follow neo-project/neo#2252. --- cli/candidate_test.go | 2 +- cli/wallet/validator.go | 8 ++++---- pkg/consensus/consensus_test.go | 4 ++-- pkg/core/native/native_neo.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/candidate_test.go b/cli/candidate_test.go index 262e05e5a..a85c68f4d 100644 --- a/cli/candidate_test.go +++ b/cli/candidate_test.go @@ -21,7 +21,7 @@ func TestRegisterCandidate(t *testing.T) { "--wallet", validatorWallet, "--from", validatorAddr, "NEO:"+validatorPriv.Address()+":10", - "GAS:"+validatorPriv.Address()+":100") + "GAS:"+validatorPriv.Address()+":10000") e.checkTxPersisted(t) e.In.WriteString("one\r") diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index dbc5f1d33..50b09d38f 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -71,14 +71,14 @@ func newValidatorCommands() []cli.Command { } func handleRegister(ctx *cli.Context) error { - return handleCandidate(ctx, "registerCandidate") + return handleCandidate(ctx, "registerCandidate", 1001*100000000) // registering costs 1000 GAS } func handleUnregister(ctx *cli.Context) error { - return handleCandidate(ctx, "unregisterCandidate") + return handleCandidate(ctx, "unregisterCandidate", -1) } -func handleCandidate(ctx *cli.Context, method string) error { +func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { wall, err := openWallet(ctx.String("wallet")) if err != nil { return cli.NewExitError(err, 1) @@ -108,7 +108,7 @@ func handleCandidate(ctx *cli.Context, method string) error { w := io.NewBufBinWriter() emit.AppCall(w.BinWriter, neoContractHash, method, callflag.WriteStates, acc.PrivateKey().PublicKey().Bytes()) emit.Opcodes(w.BinWriter, opcode.ASSERT) - tx, err := c.CreateTxFromScript(w.Bytes(), acc, -1, int64(gas), transaction.Signer{ + tx, err := c.CreateTxFromScript(w.Bytes(), acc, sysGas, int64(gas), transaction.Signer{ Account: acc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, }) diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index f67ef00e8..39f74e224 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -59,7 +59,7 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3 acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(native.NEOTotalSupply), nil) emit.Opcodes(w.BinWriter, opcode.ASSERT) emit.AppCall(w.BinWriter, bc.UtilityTokenHash(), "transfer", callflag.All, - acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(1_000_000_000), nil) + acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(10000_000_000_000), nil) emit.Opcodes(w.BinWriter, opcode.ASSERT) require.NoError(t, w.Err) @@ -78,7 +78,7 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3 emit.AppCall(w.BinWriter, bc.GoverningTokenHash(), "registerCandidate", callflag.All, newPriv.PublicKey().Bytes()) require.NoError(t, w.Err) - tx = transaction.New(netmode.UnitTestNet, w.Bytes(), 20_000_000) + tx = transaction.New(netmode.UnitTestNet, w.Bytes(), 1001_00000000) tx.ValidUntilBlock = bc.BlockHeight() + 1 tx.NetworkFee = 20_000_000 tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}} diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 43ebcc201..40967d0e2 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -115,7 +115,7 @@ func newNEO() *NEO { desc = newDescriptor("registerCandidate", smartcontract.BoolType, manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) - md = newMethodAndPrice(n.registerCandidate, 5000000, callflag.WriteStates) + md = newMethodAndPrice(n.registerCandidate, 1000_00000000, callflag.WriteStates) n.AddMethod(md, desc) desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,