Forum Home
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular

    Regtest Mode development for Feathercoin 0.9.6.2

    Technical Development
    3
    19
    8662
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wrapper
      wrapper Moderators last edited by wrapper

      RegTest version now building blocks, 1 by one. So, made some progress :

       ~/Feathercoin/src$ ./feathercoin-cli -regtest getblockchaininfo
       {
          "chain" : "regtest",
          "blocks" : 5,
          "bestblockhash" : "84b44ec0bf52a1349c79809d64c512ea64de5c873828fa2ac39148293cde6b98",
          "difficulty" : 0.00000000,
          "verificationprogress" : 1.00000000,
          "chainwork" :  "000000000000000000000000000000000000000000000000000000000000001e"
       }
      

      error message

       terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
       what():  boost: mutex lock failed in pthread_mutex_lock: Invalid argument
      
      1 Reply Last reply Reply Quote 0
      • wrapper
        wrapper Moderators last edited by wrapper

        RegTest debugging

        Regtest script setgenerate is run from :

        /Feathercoin/contrib/bitrpc/bitrpc.py

         elif cmd == "setgenerate":
             try:
                 gen= raw_input("Generate? (true/false): ")
                 cpus = raw_input("Max processors/cores (-1 for unlimited, optional):")
                 try:
                     print access.setgenerate(gen, cpus)
                 except:
                     print access.setgenerate(gen)
             except:
        

        However get error :

        ./feathercoin-cli -regtest setgenerate true 101 1
        
        error: {"code":-1,"message":"setgenerate generate ( genproclimit )\n\nSet 'generate' true or false to turn generation on or off.\nGeneration is limited to 'genproclimit' processors, -1 is unlimited.\nSee the getgenerate call for the current setting.\n\nArguments:\n1. generate         (boolean, required) Set to true to turn on generation, off to turn off.\n2. genproclimit     (numeric, optional) Set the processor limit for when generation is on. Can be -1 for unlimited.\n                    Note: in -regtest mode, genproclimit controls how many blocks are generated immediately.\n\nExamples:\n\nSet the generation on with a limit of one processor\n> feathercoin-cli setgenerate true 1\n\nCheck the setting\n> feathercoin-cli getgenerate \n\nTurn off generation\n> feathercoin-cli setgenerate false\n\nUsing json rpc\n> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"setgenerate\", \"params\": [true, 1] }' -H 'content-type: text/plain;' http://127.0.0.1:9337/\n"}
        

        So try ./feathercoin-cli -regtest setgenerate true 4

        i.e. generate = true
        number of cpu cores = 4

         ./feathercoin-cli -regtest getblockchaininfo
         {
             "chain" : "regtest", 
             "blocks" : 11,
             "bestblockhash" : "91750ef4a6f96500a2b76f00e38823f1f230919f58a2051184e17a44f7bdaf8d",
             "difficulty" : 0.00000000,
             "verificationprogress" : 1.00000000,
             "chainwork" : "0000000000000000000000000000000000000000000000000000000000000031"
         }
        
        1 Reply Last reply Reply Quote 0
        • wrapper
          wrapper Moderators last edited by

          https://github.com/bitcoin/bitcoin/search?utf8=✓&q=getgenerate(&type=

          doc/release-notes/release-notes-0.13.0.md
          Showing the top match Last indexed on 18 Oct 2016
          createwitnessaddress, addwitnessaddress.

          • Removed RPC commands: setgenerate, getgenerate.

          • New options were added to fundrawtransaction: includeWatching, changeAddress, changePosition and feeRate.

          1 Reply Last reply Reply Quote 0
          • wrapper
            wrapper Moderators last edited by wrapper

            https://github.com/bitcoin/bitcoin/issues/4242

            If you run setgenerate true too rapidly in regtest mode, bitcoind can crash with
            
            /home/ubuntu/install/include/boost/thread/pthread/condition_variable_fwd.hpp:81: boost::condition_variable::~condition_variable(): Assertion `!ret' failed.
            
            This was reproduced with the Linux 64bit gitian binary. 
            
            Sometimes it kills bitcoind without a visible asert failure. Sometimes bitcoind just misses the RPC entirely without any visible error and without killing bitcoind.
            
            1 Reply Last reply Reply Quote 0
            • wrapper
              wrapper Moderators last edited by

              [FAQ] Where are coins generated, in software terms?

              Regtest and Testnet are special cases of normal mining.

              Each has a set of parameters, ports and directories to work with but otherwise goes through the same code.

              Testnet set-ups are done to test an event, like a fork, regression testing is similar but does not connect to the internet.

              Instead of a miner regtest uses ./feathercoin-cli and passed commands to feathercoind to mine some coins.

               ./feathercoin-cli -regtest setgenerate true 1
              

              setgenerate is deprecated and the new command will be generate for later (than 0.9.6.2) versions.

              miner.cpp

               void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) 
               {
                   static boost::thread_group* minerThreads = NULL;
                   printf("Here in coin generation\n"); // RegTest Debug
                   if (nThreads < 0) {
                       if (Params().NetworkID() == CChainParams::REGTEST)
                           nThreads = 1;
                       else
                           nThreads = boost::thread::hardware_concurrency();
                  }
              
                   if (minerThreads != NULL)
                   {
                      minerThreads->interrupt_all();
                       delete minerThreads;
                       minerThreads = NULL;
                   }
              
                   if (nThreads == 0 || !fGenerate)
                       return;
              
                   minerThreads = new boost::thread_group();
                   for (int i = 0; i < nThreads; i++)
                      minerThreads->create_thread(boost::bind(&FeathercoinMiner, pwallet));
               }
              
              1 Reply Last reply Reply Quote 0
              • wrapper
                wrapper Moderators last edited by wrapper

                Current status getting regtest running :

                Various issues are affecting how complex it is to set up regtest. Whilst some are addressed there is still an unknown issue.

                Creating Genesis Block and regtest directory

                ./feathercoind -regtest -listen=0 -debug -daemon
                Searching for genesis block...
                genesis.nTime = 1396255061 
                genesis.nNonce = 3250989159 
                genesis.nVersion = 3 
                genesis.hashMerkleRoot = 97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9 
                genesis.GetHash = 29d5f68acf1fb95303120bb51c35a32d270bd736235f928de49b94d87a3782a8
                Feathercoin server starting
                
                ReserverKeyFromPool 1.1 - wallet.cpp
                ReserverKeyFromPool 1.2 - wallet.cpp
                ReserverKeyFromPool 1.3 - wallet.cpp
                ReserverKeyFromPool 2.1 - wallet.cpp
                ReserverKeyFromPool 2.2 - wallet.cpp 
                ReserverKeyFromPool 2.3 - wallet.cpp
                ReserverKeyFromPool 3.1 - wallet.cpp
                ReserverKeyFromPool 3.2 - wallet.cpp
                ReserverKeyFromPool 3.3 - wallet.cpp
                ReserverKeyFromPool 3.4 - wallet.cpp
                ReserverKeyFromPool 4.1 - wallet.cpp
                

                Getting Blockchain info :

                 ./feathercoin-cli -regtest getblockchaininfo
                 {
                 "chain" : "regtest",
                 "blocks" : 0,
                 "bestblockhash" : "29d5f68acf1fb95303120bb51c35a32d270bd736235f928de49b94d87a3782a8",
                 "difficulty" : 0.00000000,
                 "verificationprogress" : 1.00000000,
                 "chainwork" : "0000000000000000000000000000000000000000000000000000000000000002"
                  }
                
                generatebitcoins 1.1 - rpcmining.cpp
                FeathercoinMiner
                FeathercoinMiner 2
                FeathercoinMiner 2.1
                FeathercoinMiner 2.2
                In CreateNewBlockWithKey 1 miner.cpp
                InGetReservedKey 1.1-wallet.cpp
                InGetReservedKey 1.1.1-wallet.cpp
                ReserverKeyFromPool 1.1 - wallet.cpp
                ReserverKeyFromPool 1.2 - wallet.cpp
                ReserverKeyFromPool 1.3 - wallet.cpp
                

                Where it is hanging on creating a block, whilst getting a public key in wallet.dat :

                void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool)
                {
                    printf("ReserverKeyFromPool 1.1 - wallet.cpp\n"); // RegTest Debug
                    nIndex = -1;
                    printf("ReserverKeyFromPool 1.2 - wallet.cpp\n", keypool.vchPubKey); // RegTest Debug
                    keypool.vchPubKey = CPubKey();
                    printf("ReserverKeyFromPool 1.3 - wallet.cpp\n"); // RegTest Debug
                    {
                        LOCK(cs_wallet);
                        printf("ReserverKeyFromPool 2.1 - wallet.cpp\n"); // RegTest Debug
                        if (!IsLocked()) {
                        printf("ReserverKeyFromPool 2.2 - wallet.cpp\n"); // RegTest Debug          
                            TopUpKeyPool();
                        printf("ReserverKeyFromPool 2.3 - wallet.cpp\n"); // RegTest Debug
                        }
                        // Get the oldest key
                        if(setKeyPool.empty())
                            return;
                        printf("ReserverKeyFromPool 3.1 - wallet.cpp\n"); // RegTest Debug
                        CWalletDB walletdb(strWalletFile);
                        printf("ReserverKeyFromPool 3.2 - wallet.cpp\n"); // RegTest Debug
                        nIndex = *(setKeyPool.begin());
                        printf("ReserverKeyFromPool 3.3 - wallet.cpp\n"); // RegTest Debug
                        setKeyPool.erase(setKeyPool.begin());
                        printf("ReserverKeyFromPool 3.4 - wallet.cpp\n"); // RegTest Debug
                        if (!walletdb.ReadPool(nIndex, keypool))
                        throw runtime_error("ReserveKeyFromKeyPool() : read failed");
                        if (!HaveKey(keypool.vchPubKey.GetID()))
                        throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
                        assert(keypool.vchPubKey.IsValid());
                        printf("ReserverKeyFromPool 4.1 - wallet.cpp\n"); // RegTest Debug
                        // if (fDebug) LogPrintf("keypool reserve %d\n", nIndex);
                

                Which is called from miner.cpp :

                CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)  
                {
                    CPubKey pubkey;
                    printf("In CreateNewBlockWithKey 1 miner.cpp\n"); //RegTest Debug
                    if (!reservekey.GetReservedKey(pubkey)) {
                        printf("In CreateNewBlockWithKey !reservekey.GetReservedKey(pubkey)) 1.1 miner.cpp\n"); //RegTest Debug
                        return NULL;
                    }
                    printf("In CreateNewBlockWithKey 2 miner.cpp\n"); //RegTest Debug
                    CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
                    printf("In CreateNewBlockWithKey 3 miner.cpp\n"); //RegTest Debug
                    return CreateNewBlock(scriptPubKey);
                }
                
                1 Reply Last reply Reply Quote 0
                • wrapper
                  wrapper Moderators last edited by wrapper

                  rpcmining.cpp ~L176

                  ./feathercoin-cli -regtest setgenerate true 1

                  // -regtest mode: don't return until nGenProcLimit blocks are generated
                  if (fGenerate && Params().NetworkID() == CChainParams::REGTEST)
                  {
                      printf("generate   5.1 rpcmining.cpp\n"); //RegTest Debug
                      int nHeightStart = 0;
                      int nHeightEnd = 0;
                      int nHeight = 0;
                      int nGenerate = (nGenProcLimit > 0 ? nGenProcLimit : 1);
                      {   // Don't keep cs_main locked
                          printf("generate   5.2 lock rpcmining.cpp\n"); //RegTest Debug
                          LOCK(cs_main);
                          nHeightStart = chainActive.Height();
                          nHeight = nHeightStart;
                          nHeightEnd = nHeightStart+nGenerate;
                      }
                      int nHeightLast = -1;
                      while (nHeight < nHeightEnd)
                      {
                          if (nHeightLast != nHeight)
                          {
                              nHeightLast = nHeight;
                              printf("generate   5.3 Generate in rpcmining.cpp\n"); //RegTest Debug
                              GenerateBitcoins(fGenerate, pwalletMain, 1);
                              
                          }
                          MilliSleep(1);
                          {   // Don't keep cs_main locked
                              LOCK(cs_main);
                              nHeight = chainActive.Height();
                          }
                          printf("generate   5.4 Generate out rpcmining.cpp: nheight %d Start %d End %d Last %d \n", nHeight, nHeightStart, nHeightEnd, nHeightLast ); //RegTest Debug
                      }
                      printf("generate   5.5 out rpcmining.cpp\n"); //RegTest Debug
                  }
                  else // Not -regtest: start generate thread, return immediately
                  {
                      mapArgs["-gen"] = (fGenerate ? "1" : "0");
                      mapArgs ["-genproclimit"] = itostr(nGenProcLimit);
                      GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit);
                  }
                  
                  return Value::null;
                  }
                  

                  Output

                   generate   5.4 Generate out rpcmining.cpp: nheight 0 Start 0 End 1 Last 0 
                   generate   5.4 Generate out rpcmining.cpp: nheight 0 Start 0 End 1 Last 0 
                   generate   5.4 Generate out rpcmining.cpp: nheight 0 Start 0 End 1 Last 0 
                   generate   5.4 Generate out rpcmining.cpp: nheight 0 Start 0 End 1 Last 0
                  
                  1 Reply Last reply Reply Quote 0
                  • wrapper
                    wrapper Moderators last edited by

                    miner.cpp L683

                    GenerateBitcoins called from rpcmining.cpp

                    void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
                    {
                        printf("In GenerateBitcoins - 1.1  L664 miner.cpp \n"); // RegTest Debug
                        static boost::thread_group* minerThreads = NULL;
                        printf("In GenerateBitcoins - 1.2  - miner.cpp \n"); // RegTest Debug
                        if (nThreads < 0) {
                            if (Params().NetworkID() == CChainParams::REGTEST)
                                nThreads = 1;
                            else
                                nThreads = boost::thread::hardware_concurrency();
                        }
                        printf("In GenerateBitcoins - 1.3  miner threads miner.cpp \n"); // RegTest Debug
                        if (minerThreads != NULL)
                        {
                            minerThreads->interrupt_all();
                            delete minerThreads;
                            minerThreads = NULL;
                        }
                    
                        if (nThreads == 0 || !fGenerate)
                            return;
                        printf("In GenerateBitcoins - 1.4  create thread miner.cpp \n"); // RegTest Debug
                        minerThreads = new boost::thread_group();
                        printf("In GenerateBitcoins - 1.5  create miners miner.cpp \n"); // RegTest Debug
                        for (int i = 0; i < nThreads; i++)
                            minerThreads->create_thread(boost::bind(&FeathercoinMiner, pwallet));
                           printf("In GenerateBitcoins - 1.6  exiting GenerateBitcoins \n"); // RegTest Debug
                        }
                    
                    1 Reply Last reply Reply Quote 0
                    • wrapper
                      wrapper Moderators last edited by

                      RegTest is now working in the test version, Scrypt only. It need setting up to do that, so I’ll try resetting it up with the fixes @Bushstar has done to the 0.9.6.x series - Scrypt / Neoscrypt interface.

                       {
                      "chain" : "regtest",
                      "blocks" : 222,
                      "bestblockhash" : "95ce08426d17cfb6bc6bf519d479ec0c2f29827c7165fd71d0a005d8877c8768",
                      "difficulty" : 0.00000000,
                      "verificationprogress" : 1.00000000,
                      "chainwork" : "00000000000000000000000000000000000000000000000000000000000000e0"
                      }
                      
                      1 Reply Last reply Reply Quote 0
                      • wrapper
                        wrapper Moderators last edited by wrapper

                        RegTest is now working with scrypt, just clearing up a few anomalies with the halving calculation and testing it.

                        The calculation should include nSubsidyHalvingInterval = 256; from chainparams.cpp …

                         int64_t GetBlockValue(int nHeight, int64_t nFees)
                         {    
                             int64_t nSubsidy = 200 * COIN;
                        
                        	    if(nHeight >= nForkThree || (TestNet() || RegTest()) )
                        		     nSubsidy = 80 * COIN;
                        
                             // Halving subsidy happens every 2,100,000 blocks. The code below takes account for the
                             // fact that the first 204,639 blocks took 2.5 minutes and after changed to 1 minute.
                             nSubsidy >>= (nHeight + 306960) / 2100000;
                             return nSubsidy + nFees;  
                         }
                        

                        Trying this :

                         if (!RegTest()) {
                             nSubsidy >>= (nHeight + 306960) / 2100000;
                         }
                             else {
                                 int halvings = nHeight / Params().SubsidyHalvingInterval();
                                 if (halvings >= 64)
                                        return nFees;
                                 nSubsidy >>= halvings;
                             }
                        
                        1 Reply Last reply Reply Quote 0
                        • wrapper
                          wrapper Moderators last edited by wrapper

                          [FAQ] What is RegTest mode?

                          RegTest, or Regression Testing mode loads up a compact set of initiating parameters and creates a genesis block in the .feathercoin/regtest directory. Coins can created by running setgenerate (soon to be generate) in the command line interface.

                          This branch (0.9.6.2 dev) contains a working RegTest, sync speed up and Bush’s latest fixes.

                          In Regtest mode you create a test wallet and generate coins to experiment with.

                          https://github.com/FeatherCoin/Feathercoin/tree/0.9.6.2

                          RegTest now uses noescrypt. setgenerate -1 (seems to) works with the daemon, but not the wallet. The halving is set at 256

                          Pretty cool watching your generated coins come in to the wallet, although they do slow down as the difficulty increases. I’ve been through 2 halvenings.

                          After compiling : https://github.com/FeatherCoin/Feathercoin/tree/master-0.9/doc

                          cd ~/Feathercoin/src
                          ./feathercoind -regtest -listen=0 -debug -daemon
                          
                          ./feathercoin-cli -regtest setgenerate true 300
                          
                          ./feathercoin-cli -regtest getinfo
                          

                          To start up a test wallet in Regression Test mode

                          cd ~/Feathercoin/src/qt
                          
                          ./feathercoin-qt -regtest -listen=0 -debug
                          
                          1 Reply Last reply Reply Quote 2
                          • Cookieboy
                            Cookieboy Regular Member last edited by

                            Latest version in development 0.9.6.2 has the fixes in it to make this function! Thank you @wrapper and @Bushstar for your hard work on it.

                            1 Reply Last reply Reply Quote 2
                            • Wellenreiter
                              Wellenreiter Moderators last edited by

                              Well done Gentlemen ::thumbsup:

                              :D

                              Feathercoin development donation address: 6p8u3wtct7uxRGmvWr2xvPxqRzbpbcd82A
                              Openpgp key: 0x385C34E77F0D74D7 (at keyserver.ubuntu.com)/fingerprint: C7B4 E9EA 17E1 3D12 07AB 1FDB 385C 34E7 7F0D 74D7

                              1 Reply Last reply Reply Quote 1
                              • First post
                                Last post