0

I used hardhat to deploy a contract to my private chain. I got a error that said:

HeadersTimeoutError: Headers Timeout Error
    at Timeout.onParserTimeout [as callback] (C:\Users\sol2\test\node_modules\undici\lib\client.js:931:28)
    at Timeout.onTimeout [as _onTimeout] (C:\Users\sol2\test\node_modules\undici\lib\timers.js:20:13)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7) {
  code: 'UND_ERR_HEADERS_TIMEOUT'
}

I build a private chain by geth :

geth --datadir block2 --networkid 123456 --nodiscover --http --http.port 8001 --rpc.gascap 0 --rpc.txfeecap 0 --allow-insecure-unlock  console

deployed contract is:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SC_j {
    uint256 public task_time;
    uint256 public num_of_people;
    uint256 public reward;
    uint256 public staking;
    string internal PK_CA;
    string internal PK_req;
    string public cert_req;
    string public data;
    address[] internal verifiers;
    bytes32[] public ans_hash;
    uint256[] public ans;
    struct vi {
        bool task_accept;
        bytes32 xvi;
        string cert;
        string DecryCert;
        uint256 ID;
        uint256 unixTimeStamp_expire;
        bytes pk;
        uint256 ans;
        bytes32 proof;
        uint256 reputation;
    }
    mapping(uint => uint) public ans_count;
    mapping(address => vi) public verifier; 
    constructor(uint256 reward_, uint256 num_, uint256 time, string memory data_, string memory cert, string memory req_pk, string memory CA_pk, uint256[] memory ans_) {
        for(uint i=0;i<ans_.length;i++) {
            ans.push(ans_[i]);
        }
        cert_req = cert;
        PK_CA = CA_pk;
        PK_req = req_pk;
        data = data_;
        reward = reward_;
        num_of_people = num_;
        task_time = block.timestamp + time*60;
        bytes32 ans_1 = keccak256(abi.encodePacked(ans[0]));
        bytes32 ans_2 = keccak256(abi.encodePacked(ans[1]));
        ans_hash.push(ans_1);
        ans_hash.push(ans_2);
    }
    function Accept_task(string memory cert, string memory Decert, uint ID, uint unixTimeStamp, bytes memory pk) public payable returns(bool) {
        require(msg.value == reward/num_of_people, "Wrong value!");
        require(address(bytes20(uint160(uint256(keccak256(pk))))) == msg.sender, "You couldn't use this certificate");
        require(unixTimeStamp > block.timestamp + task_time, "Your certificate would expired when the ans doesn't aggregate successfully yet.");
        staking += msg.value;
        verifiers.push(msg.sender);
        verifier[msg.sender].cert = cert;
        verifier[msg.sender].DecryCert = Decert;
        verifier[msg.sender].task_accept = true;
        verifier[msg.sender].ID = ID;
        verifier[msg.sender].unixTimeStamp_expire = unixTimeStamp;
        verifier[msg.sender].pk = pk;
        return (true);
    }

    function Stake_Price() view public returns(uint) {
        return (1000000000000000 * reward/num_of_people);
        //*(1-verifier[msg.sender].reputation));
    }
    
    function provideXvi(bytes32 xvi, bytes32 proof) public returns(bool) { //string memory, string memory, string memory) {
        require(verifier[msg.sender].task_accept, "You have not accepted this task.");
        verifier[msg.sender].xvi = xvi;
        verifier[msg.sender].proof = proof;
        return (true);
    }

    function Aggregate_answer(uint256 random_num, uint256 rep) public  returns(uint x) {
        require(verifier[msg.sender].task_accept, "You have not accepted this task.");
        require(block.timestamp >= task_time, "It's not a time to aggregate answer.");
        bytes32 ran_hash = keccak256(abi.encodePacked(random_num));
        if(keccak256(abi.encodePacked(ans_hash[0], ran_hash)) == verifier[msg.sender].xvi) {
            ans_count[ans[0]] = ans_count[ans[0]] + rep*10000;
            verifier[msg.sender].ans = 0;
            return (ans[0]);
        }
        else if(keccak256(abi.encodePacked(ans_hash[1], ran_hash)) == verifier[msg.sender].xvi) {
            ans_count[ans[1]] = ans_count[ans[1]] + rep*10000;
            verifier[msg.sender].ans = 1;
            return (ans[1]);
        }
    }

    function show_ans() view public returns(uint) {
        require(block.timestamp >= task_time + 86400, "It isn't a time to show answer");
        if(ans_count[ans[0]] > ans_count[ans[1]])
            return ans[0];
        else 
            return ans[1];
    }

    function withdraw_reward(bytes32 proof_) public {
        require(block.timestamp >= task_time + 172800, "It isn't a time to withdraw reward");
        require(verifier[msg.sender].task_accept);
        require(address(bytes20(uint160(uint256(keccak256(verifier[msg.sender].pk))))) == msg.sender, "You couldn't use this certificate");
        require(proof_ == verifier[msg.sender].proof, "Your proof is not the same with the previous one.");
        payable(address(this)).transfer(reward/ans_count[verifier[msg.sender].ans]);
    }
    function setReward(uint256 x) public {
        reward = x;
    }
    fallback() external{}
} 

Hardhat deploy script is:

async function main() {
    const reward = ethers.parseEther("1")
    const Task = await ethers.getContractFactory("SC_j");
    const data = "test data"
    const cert = "00000116936590690xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    const req_pk = "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    const CA_pk =  "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    const ans_ = [1,2]
    const task = await Task.deploy(reward, 1000, 1, data, cert, req_pk, CA_pk, ans_, {value:reward, gas:ethers.parseEther("1")})
    await task.waitForDeployment();
    console.log("deploying succ")
}

and hardhat.config.js is :

require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.0",
  networks: {
    hardhat:{},
    private:{
      blockGasLimit: 0xffffffffffffffff,
      url:"http://127.0.0.1:8001",
      accounts:["My private key"],
      allowUnlimitedContractSize:true,
      chainId:123456,
    }
  }
};

I believe that it caused by gas fee, but I already set the --rpc.gascap 0 --rpc.txfeecap 0 flags and it can't work properly as well.

I would like to ask that how should I do to make it deployed properly ?

SpaceNinja
  • 31
  • 1

0 Answers0