@@ -2229,16 +2229,18 @@ bool BitcoindRPCCheck(const bool init)
22292229 vblocksToReconsiderAgain.clear ();
22302230 pblocktree->WriteInvalidBlockQueue (vblocksToReconsider);
22312231
2232- // Next, check for working rpc
2232+ // Next, check for working and valid rpc
22332233 if (GetBoolArg (" -validatepegin" , DEFAULT_VALIDATE_PEGIN)) {
22342234 // During init try until a non-RPC_IN_WARMUP result
22352235 while (true ) {
22362236 try {
2237+ // The first thing we have to check is the version of the node.
22372238 UniValue params (UniValue::VARR);
2238- params.push_back (UniValue (0 ));
2239- UniValue reply = CallRPC (" getblockhash" , params, true );
2240- UniValue error = find_value (reply, " error" );
2239+ UniValue reply = CallRPC (" getnetworkinfo" , params, true );
2240+ UniValue error = reply[" error" ];
22412241 if (!error.isNull ()) {
2242+ // On the first call, it's possible to node is still in
2243+ // warmup; in that case, just wait and retry.
22422244 if (error[" code" ].get_int () == RPC_IN_WARMUP) {
22432245 MilliSleep (1000 );
22442246 continue ;
@@ -2249,6 +2251,22 @@ bool BitcoindRPCCheck(const bool init)
22492251 }
22502252 }
22512253 UniValue result = reply[" result" ];
2254+ if (!result.isObject () || !result.get_obj ()[" version" ].isNum () ||
2255+ result.get_obj ()[" version" ].get_int () < MIN_PARENT_NODE_VERSION) {
2256+ LogPrintf (" ERROR: Parent chain daemon too old; "
2257+ " need Bitcoin Core version 0.16.2 or newer.\n " );
2258+ return false ;
2259+ }
2260+
2261+ // Then check the genesis block to correspond to parent chain.
2262+ params.push_back (UniValue (0 ));
2263+ reply = CallRPC (" getblockhash" , params, true );
2264+ error = reply[" error" ];
2265+ if (!error.isNull ()) {
2266+ LogPrintf (" ERROR: Bitcoind RPC check returned 'error' response.\n " );
2267+ return false ;
2268+ }
2269+ result = reply[" result" ];
22522270 if (!result.isStr () || result.get_str () != Params ().ParentGenesisBlockHash ().GetHex ()) {
22532271 LogPrintf (" ERROR: Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?\n " );
22542272 return false ;
@@ -2304,7 +2322,7 @@ bool BitcoindRPCCheck(const bool init)
23042322
23052323 // Write back remaining blocks
23062324 pblocktree->WriteInvalidBlockQueue (vblocksToReconsiderAgain);
2307- }
2325+ }
23082326 return true ;
23092327}
23102328
0 commit comments