비트캔디 난이도 조정함수 18년5월1일

in #cdy6 years ago (edited)

04tmp.png

캔디의 난이도 조정 함수에서 난이도 변동을 제어하는 부분이 있습니다. 이 부분을 변경하면 빠르게 난이도 대응 할 수 있습니다.

https://github.com/bitcoincandyofficial/bitcoincandy/blob/master/src/pow.cpp

위 파일의 난이도 함수는 LwmaGetNextWorkRequired와 LwmaCalculateNextWorkRequired입니다.

arith_uint256 sum_target;
int sum_time = 0, nWeight = 0;

// Loop through N most recent blocks.
for (int i = height - N; i < height; i++) {
    const CBlockIndex* block = pindexPrev->GetAncestor(i);
    const CBlockIndex* block_Prev = block->GetAncestor(i - 1);
    int64_t solvetime = block->GetBlockTime() - block_Prev->GetBlockTime();

    nWeight++;
    sum_time += solvetime * nWeight;  // Weighted solvetime sum. The nearsest blocks get the most weight. 
    
    // Target sum divided by a factor, (k N^2).
    // The factor is a part of the final equation. However we divide sum_target here to avoid
    // potential overflow.
    arith_uint256 target;
    target.SetCompact(block->nBits);
    sum_target += target ;   // (k * N * N);
}


// Keep t reasonable in case strange solvetimes occurred.
if (sum_time < N * N * T / 20) {
    sum_time = N * N * T / 20;
}

const arith_uint256 pow_limit = UintToArith256(params.PowLimit(true));

arith_uint256 next_target = 2 * (sum_time/(N*(N+1)))* (sum_target/N) * adjust/T; // next_target = LWMA * avgTarget * adjust /T;

next-target값이 높으면 쉽게 블럭을 찾는것 같습니다. 정상적인경우에 sum_time은 N(N+1)T/2 정도입니다.

위에서 sum_time 이 너무 낮을때 최소값으로 NNT/20으로 설정합니다. sum_time값이 낮아지면 next_target 값이 낮아져서 블럭찾기 어려워집니다(난이도 증가). sum_time이 충분히 적어질때도 커버하려면 위 if문 조건을 수정하면 됩니다.
// Keep t reasonable in case strange solvetimes occurred.
if (sum_time < N * N * T / 20) {
sum_time = N * N * T / 20;
}

581683블럭 9시17분
581646블럭 9시 8분 9분동안 37개발견 8.2배 속도로 발견

581645블럭 8시8분
581624블럭 7시 53분 15분동안 21개발견 2.8배 속도로 발견

581623블럭 7시21분
581567블럭 7시 12분 9분동안 56개발견 12.4배 속도로 발견

대략 심할때 10배까지 빠른 속도로 채굴이 이뤄지므로 현재보다 next_target대응을 10배 정도 높여야 합니다. 그래서 sum_time 하한을 NNT/200으로 바꾸면 됩니다.
// Keep t reasonable in case strange solvetimes occurred.
if (sum_time < N * N * T / 200) {
sum_time = N * N * T / 200;
}

만약 200을 500~600까지 더 올리면 해시몰릴때 더 빠르게 대응해서 블럭타임이 2분으로 더 빠르게 다가갑니다.

비트캔디의 난이도 함수는 매우 합리적인데 위 조건만 넣어주면 고래채굴자의 횡포를 충분히 막을 수 있을것입니다. 이 자료가 캔디 개발진에게 전달되길 바랍니다.

Sort:  
Loading...

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.029
BTC 57087.02
ETH 3064.71
USDT 1.00
SBD 2.19