Bitcoin ABC  0.22.12
P2P Digital Currency
abc.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <config.h>
6 #include <consensus/consensus.h>
7 #include <rpc/server.h>
8 #include <rpc/util.h>
9 #include <sync.h>
10 #include <util/strencodings.h>
11 #include <util/string.h>
12 #include <validation.h>
13 
14 #include <univalue.h>
15 
16 static UniValue getexcessiveblock(const Config &config,
17  const JSONRPCRequest &request) {
18  RPCHelpMan{
19  "getexcessiveblock",
20  "Return the excessive block size.",
21  {},
22  RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"},
23  RPCExamples{HelpExampleCli("getexcessiveblock", "") +
24  HelpExampleRpc("getexcessiveblock", "")},
25  }
26  .Check(request);
27 
29  ret.pushKV("excessiveBlockSize", config.GetMaxBlockSize());
30  return ret;
31 }
32 
34  const JSONRPCRequest &request) {
35  RPCHelpMan{
36  "setexcessiveblock",
37  "DEPRECATED. Set the excessive block size. Excessive blocks will not "
38  "be used in the active chain or relayed. This discourages the "
39  "propagation of blocks that you consider excessively large.",
40  {
42  "Excessive block size in bytes. Must be greater than " +
44  },
45  RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"},
46  RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") +
47  HelpExampleRpc("setexcessiveblock", "25000000")},
48  }
49  .Check(request);
50 
51  if (!IsDeprecatedRPCEnabled(gArgs, "setexcessiveblock")) {
52  // setexcessiveblock is deprecated in v0.22.12 for removal in v0.23
53  throw JSONRPCError(
55  std::string(
56  "The setexcessiveblock RPC is deprecated and will be removed "
57  "in a future version. Use the -deprecatedrpc=setexcessiveblock "
58  "option to continue using it."));
59  }
60 
61  if (!request.params[0].isNum()) {
62  throw JSONRPCError(
64  std::string(
65  "Invalid parameter, excessiveblock must be an integer"));
66  }
67 
68  int64_t ebs = request.params[0].get_int64();
69 
70  // Do not allow maxBlockSize to be set below historic 1MB limit
71  if (ebs <= int64_t(LEGACY_MAX_BLOCK_SIZE)) {
72  throw JSONRPCError(
74  std::string(
75  "Invalid parameter, excessiveblock must be larger than ") +
77  }
78 
79  // Set the new max block size.
80  {
81  LOCK(cs_main);
82  if (!config.SetMaxBlockSize(ebs)) {
83  throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected error");
84  }
85  }
86 
87  // settingsToUserAgentString();
88  std::ostringstream ret;
89  ret << "Excessive Block set to " << ebs << " bytes.";
90  return UniValue(ret.str());
91 }
92 
94  // clang-format off
95  static const CRPCCommand commands[] = {
96  // category name actor (function) argNames
97  // ------------------- ------------------------ ---------------------- ----------
98  { "network", "getexcessiveblock", getexcessiveblock, {}},
99  { "network", "setexcessiveblock", setexcessiveblock, {"maxBlockSize"}},
100  };
101  // clang-format on
102 
103  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) {
104  t.appendCommand(commands[vcidx].name, &commands[vcidx]);
105  }
106 }
bool IsDeprecatedRPCEnabled(const ArgsManager &args, const std::string &method)
Definition: server.cpp:387
Bitcoin RPC command dispatcher.
Definition: server.h:198
static UniValue setexcessiveblock(Config &config, const JSONRPCRequest &request)
Definition: abc.cpp:33
Required arg.
#define ARRAYLEN(array)
Utilities for converting data from/to strings.
Definition: strencodings.h:19
bool isNum() const
Definition: univalue.h:94
int64_t get_int64() const
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:316
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
static UniValue getexcessiveblock(const Config &config, const JSONRPCRequest &request)
Definition: abc.cpp:16
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:67
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:143
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:52
virtual uint64_t GetMaxBlockSize() const =0
Definition: config.h:19
UniValue params
Definition: request.h:37
#define LOCK(cs)
Definition: sync.h:230
const char * name
Definition: rest.cpp:43
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:90
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:138
RPC method is deprecated.
Definition: protocol.h:60
static const uint64_t LEGACY_MAX_BLOCK_SIZE
The maximum allowed size for a block, before the UAHF.
Definition: consensus.h:18
void RegisterABCRPCCommands(CRPCTable &t)
Register ABC RPC commands.
Definition: abc.cpp:93
ArgsManager gArgs
Definition: system.cpp:76
virtual bool SetMaxBlockSize(uint64_t maxBlockSize)=0