Quorum Ethereum Truffle) Ошибка: номер может безопасно хранить только до 53 бит - PullRequest
0 голосов
/ 10 января 2019

Я на самом деле учусь умному контрактному программированию на ethereum и работаю с трюфелем. Прямо сейчас я делаю этот урок здесь: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains

Где вы узнаете, как создать дапп с кворумом. Но теперь у меня есть проблема.

Я сделал все точно так, как описано, но когда я делаю:

truffle migrate

Я получаю эту ошибку здесь:

$ truffle migrate
    ⚠️  Important ⚠️
    If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.


    Starting migrations...
    ======================
    > Network name:    'development'
    > Network id:      10
    > Block gas limit: 3758096384


    1_initial_migration.js
    ======================

       Deploying 'Migrations'
       ----------------------
       > transaction hash:    0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
    - Blocks: 0            Seconds: 0
       > Blocks: 0            Seconds: 0
       > contract address:    0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
       > account:             0xed9d02e382b34818e88B88a309c7fe71E65f419d
       > balance:             1000000000
       > gas used:            245462
       > gas price:           0 gwei
       > value sent:          0 ETH
       > total cost:          0 ETH


    - Saving migration to chain.
    Error: Number can only safely store up to 53 bits
        at assert (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:6:1)
        at BN.toNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:506:1)
        at Object.hexToNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-utils\src\utils.js:234:1)
        at Method.outputBlockFormatter [as outputFormatter] (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-helpers\src\formatters.js:239:1)
        at Method.formatOutput (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:163:1)
        at sendTxCallback (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:473:1)
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:147:1
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:145:1
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
        at XMLHttpRequest.request.onreadystatechange (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)
        at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
        at XMLHttpRequest._setReadyState (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
        at XMLHttpRequest._onHttpResponseEnd (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
        at IncomingMessage.<anonymous> (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)
        at emitNone (events.js:111:20)
        at IncomingMessage.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1064:12)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
    Truffle v5.0.1 (core: 5.0.1)
    Node v8.11.4

Теперь я не знаю, почему ...

У кого-нибудь есть такая же проблема, и она может мне помочь?

Это мой умный контракт:

pragma solidity ^0.4.17;

contract SimpleStorage {
  uint public storedData;

  constructor(uint initVal) public {
    storedData = initVal;
  }

  function set(uint x) public {
    storedData = x;
  }

  function get() view public returns (uint retVal) {
    return storedData;
  }
}

И мой файл truffle-config.js:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 22000, // was 8545
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 22003,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 22006,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    }
  },
  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.4.25",    // Fetch exact version from solc-bin (default: truffle's version)
    }
  }
}

И файл миграции:

var SimpleStorage = artifacts.require("SimpleStorage");

module.exports = function(deployer) {
  // Pass 42 to the contract as the first constructor parameter
  deployer.deploy(SimpleStorage, 2, { privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="] })
};

Ответы [ 5 ]

0 голосов
/ 03 июня 2019

Простое исправление: просто добавьте type: "quorum" в свой трюфель-конфиг для сети, которая должна работать в кворуме.

0 голосов
/ 22 марта 2019

Вам не нужно использовать прокси, если вы понизили версию трюфеля до 4.1.15. Если вы сделаете это, все будет работать нормально. Только не переходите на 4.1.14, потому что трюфельный инициат в этом пакете не работает!

0 голосов
/ 22 января 2019

@ QuorumPrivateBlockChain Эй, приятель.

Итак, это мой файл truffle-config.js:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 7546,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 7547,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    }
  },
  compilers: {
    solc: {
      version: "0.4.25",   
    }
  }
}

А это мой файл config.js с прокси:

module.exports = [
  {
    rpcUrl: 'http://localhost:22000',
    port: 7545
  },
  {
    rpcUrl: 'http://localhost:22003',
    port: 7546
  },
  {
    rpcUrl: 'http://localhost:22006',
    port: 7547
  },
];

Итак, что вы делаете, вы отправляете запросы от вашего трюфеля на ваш прокси, а затем прокси конвертирует метку времени и отправляет запрос дальше узлу.

Прокси сам по себе является программой, вам не нужно копировать файл config.js из кода прокси. Посмотрите в github, как вы можете запустить прокси.

0 голосов
/ 08 февраля 2019

Прокси недостаточно, потому что web3.js может получить блокировку при подписке через ws

Также при получении кворума блок по номеру не работает, он принимает только шестнадцатеричный код, однако web3.js принимает шестнадцатеричный код как blockhash

Вот мое решение

web3.extend({
  property: 'eth',
  methods: [new web3.extend.Method({
    name: 'getBlockByNumber',
    call: 'eth_getBlockByNumber',
    params: 2,
    inputFormatter: [web3.extend.formatters.inputBlockNumberFormatter, v => !!v],
    outputFormatter: web3.extend.formatters.outputBlockFormatter
  })]
});
web3.utils.hexToNumber = v => {
  if (!v) return v;
  try {
    return numberToBN(v).toNumber();
  } catch (e) {
    return numberToBN(v).toString();
  }
};

Просто позаботьтесь о том, чтобы временная метка была теперь строкой

Вот связанная проблема в репозитории web3.js https://github.com/ethereum/web3.js/issues/1215

0 голосов
/ 18 января 2019

Таким образом, проблема заключалась в том, что метка времени блока была в наносекундах.

@ edgraaff написал прокси, который преобразует метку времени из наносекунд в секунды. Вы можете найти код здесь -> https://github.com/edgraaff/quorum-rpc-proxy

Мне нужно было клонировать прокси и изменить файл config.js на:

module.exports = {
  rpcUrl: 'http://localhost:22000',
  port: 7545
};

И в файле truffle-config.js мне пришлось сменить порт. Вот код:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545, // was 8545
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 22003,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 22006,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    }
  },
  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.4.25",    // Fetch exact version from solc-bin (default: truffle's version)
    }
  }
}

Благодаря @ edgraaff

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...