REF


private 이더리움 환경을 구성해서 mining을 시켜놓으면, 쉬지 않고 mining을 한다.


혹시 이게 부담된다면

transaction이 생겼을때만 mining하는 방법이 있다.


(하드디스크나 cpu부하를 줄이기에 용이하다.)




var mining_threads = 1

function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        if (eth.mining) return;
        console.log("== Pending transactions! Mining...");
        miner.start(mining_threads);
    } else {
        miner.stop();
        console.log("== No transactions! Mining stopped.");
    }
}

eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });

checkWork();


pending블록이 있을때만 miner.start를 하고, 아닌경우 miner.stop을 하는 코드이다.


이걸 javascript로 별도저장해서 geth실행시 반영하려면

geth --preload "/path/to/mineWhenNeeded.js"  

와 같이 하면된다. 






Posted by yongary
,