-
Notifications
You must be signed in to change notification settings - Fork 0
/
work_eval.go
42 lines (34 loc) · 1.03 KB
/
work_eval.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2018 The VeChainThor developers
// Copyright (c) 2019 The PlayMaker developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package tx
import (
"math"
"math/big"
"github.com/playmakerchain/powerplay/powerplay"
)
var (
workPerGas = big.NewInt(1000)
big100 = big.NewInt(100)
big104 = big.NewInt(104) // Moore's law monthly rate (percentage)
bigE18 = big.NewInt(1e18)
)
// workToGas exchange proved work to gas.
// The decay curve follows Moore's law.
func workToGas(work *big.Int, blockNum uint32) uint64 {
gas := new(big.Int).Div(work, workPerGas)
if gas.Sign() == 0 {
return 0
}
months := new(big.Int).SetUint64(uint64(blockNum) * powerplay.BlockInterval / 3600 / 24 / 30)
if months.Sign() != 0 {
x := &big.Int{}
gas.Mul(gas, x.Exp(big100, months, nil))
gas.Div(gas, x.Exp(big104, months, nil))
}
if gas.BitLen() > 64 {
return math.MaxUint64
}
return gas.Uint64()
}