all: simplify timestamps to uint64 (#19372)
* all: simplify timestamps to uint64 * tests: update definitions * clef, faucet, mobile: leftover uint64 fixups * ethash: fix tests * graphql: update schema for timestamp * ethash: remove unused variable
This commit is contained in:
parent
e14f8a408c
commit
0b4fe8d192
|
@ -690,7 +690,7 @@ func testExternalUI(api *core.SignerAPI) {
|
||||||
big.NewInt(1337),
|
big.NewInt(1337),
|
||||||
1338,
|
1338,
|
||||||
1338,
|
1338,
|
||||||
big.NewInt(1338),
|
1338,
|
||||||
[]byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
|
[]byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
|
||||||
common.HexToHash("0x0000H45H"),
|
common.HexToHash("0x0000H45H"),
|
||||||
types.BlockNonce{},
|
types.BlockNonce{},
|
||||||
|
|
|
@ -579,7 +579,7 @@ func (f *faucet) loop() {
|
||||||
go func() {
|
go func() {
|
||||||
for head := range update {
|
for head := range update {
|
||||||
// New chain head arrived, query the current stats and stream to clients
|
// New chain head arrived, query the current stats and stream to clients
|
||||||
timestamp := time.Unix(head.Time.Int64(), 0)
|
timestamp := time.Unix(int64(head.Time), 0)
|
||||||
if time.Since(timestamp) > time.Hour {
|
if time.Since(timestamp) > time.Hour {
|
||||||
log.Warn("Skipping faucet refresh, head too old", "number", head.Number, "hash", head.Hash(), "age", common.PrettyAge(timestamp))
|
log.Warn("Skipping faucet refresh, head too old", "number", head.Number, "hash", head.Hash(), "age", common.PrettyAge(timestamp))
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -365,7 +365,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if timestamp := time.Unix(done.Latest.Time.Int64(), 0); time.Since(timestamp) < 10*time.Minute {
|
if timestamp := time.Unix(int64(done.Latest.Time), 0); time.Since(timestamp) < 10*time.Minute {
|
||||||
log.Info("Synchronisation completed", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
|
log.Info("Synchronisation completed", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
|
||||||
"age", common.PrettyAge(timestamp))
|
"age", common.PrettyAge(timestamp))
|
||||||
stack.Stop()
|
stack.Stop()
|
||||||
|
|
|
@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
|
|
||||||
// Don't waste time checking blocks from the future
|
// Don't waste time checking blocks from the future
|
||||||
if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 {
|
if header.Time > uint64(time.Now().Unix()) {
|
||||||
return consensus.ErrFutureBlock
|
return consensus.ErrFutureBlock
|
||||||
}
|
}
|
||||||
// Checkpoint blocks need to enforce zero beneficiary
|
// Checkpoint blocks need to enforce zero beneficiary
|
||||||
|
@ -321,7 +321,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
|
||||||
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
if parent.Time.Uint64()+c.config.Period > header.Time.Uint64() {
|
if parent.Time+c.config.Period > header.Time {
|
||||||
return ErrInvalidTimestamp
|
return ErrInvalidTimestamp
|
||||||
}
|
}
|
||||||
// Retrieve the snapshot needed to verify this header and cache it
|
// Retrieve the snapshot needed to verify this header and cache it
|
||||||
|
@ -540,9 +540,9 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
header.Time = new(big.Int).Add(parent.Time, new(big.Int).SetUint64(c.config.Period))
|
header.Time = parent.Time + c.config.Period
|
||||||
if header.Time.Int64() < time.Now().Unix() {
|
if header.Time < uint64(time.Now().Unix()) {
|
||||||
header.Time = big.NewInt(time.Now().Unix())
|
header.Time = uint64(time.Now().Unix())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -607,7 +607,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sweet, the protocol permits us to sign the block, wait for our time
|
// Sweet, the protocol permits us to sign the block, wait for our time
|
||||||
delay := time.Unix(header.Time.Int64(), 0).Sub(time.Now()) // nolint: gosimple
|
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple
|
||||||
if header.Difficulty.Cmp(diffNoTurn) == 0 {
|
if header.Difficulty.Cmp(diffNoTurn) == 0 {
|
||||||
// It's not our turn explicitly to sign, delay it a bit
|
// It's not our turn explicitly to sign, delay it a bit
|
||||||
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
|
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
|
||||||
|
|
|
@ -716,7 +716,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) {
|
||||||
Difficulty: big.NewInt(167925187834220),
|
Difficulty: big.NewInt(167925187834220),
|
||||||
GasLimit: 4015682,
|
GasLimit: 4015682,
|
||||||
GasUsed: 0,
|
GasUsed: 0,
|
||||||
Time: big.NewInt(1488928920),
|
Time: 1488928920,
|
||||||
Extra: []byte("www.bw.com"),
|
Extra: []byte("www.bw.com"),
|
||||||
MixDigest: common.HexToHash("0x3e140b0784516af5e5ec6730f2fb20cca22f32be399b9e4ad77d32541f798cd0"),
|
MixDigest: common.HexToHash("0x3e140b0784516af5e5ec6730f2fb20cca22f32be399b9e4ad77d32541f798cd0"),
|
||||||
Nonce: types.EncodeNonce(0xf400cd0006070c49),
|
Nonce: types.EncodeNonce(0xf400cd0006070c49),
|
||||||
|
|
|
@ -63,7 +63,6 @@ var (
|
||||||
// codebase, inherently breaking if the engine is swapped out. Please put common
|
// codebase, inherently breaking if the engine is swapped out. Please put common
|
||||||
// error types into the consensus package.
|
// error types into the consensus package.
|
||||||
var (
|
var (
|
||||||
errLargeBlockTime = errors.New("timestamp too big")
|
|
||||||
errZeroBlockTime = errors.New("timestamp equals parent's")
|
errZeroBlockTime = errors.New("timestamp equals parent's")
|
||||||
errTooManyUncles = errors.New("too many uncles")
|
errTooManyUncles = errors.New("too many uncles")
|
||||||
errDuplicateUncle = errors.New("duplicate uncle")
|
errDuplicateUncle = errors.New("duplicate uncle")
|
||||||
|
@ -242,20 +241,16 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
|
||||||
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
|
||||||
}
|
}
|
||||||
// Verify the header's timestamp
|
// Verify the header's timestamp
|
||||||
if uncle {
|
if !uncle {
|
||||||
if header.Time.Cmp(math.MaxBig256) > 0 {
|
if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) {
|
||||||
return errLargeBlockTime
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if header.Time.Cmp(big.NewInt(time.Now().Add(allowedFutureBlockTime).Unix())) > 0 {
|
|
||||||
return consensus.ErrFutureBlock
|
return consensus.ErrFutureBlock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if header.Time.Cmp(parent.Time) <= 0 {
|
if header.Time <= parent.Time {
|
||||||
return errZeroBlockTime
|
return errZeroBlockTime
|
||||||
}
|
}
|
||||||
// Verify the block's difficulty based in it's timestamp and parent's difficulty
|
// Verify the block's difficulty based in it's timestamp and parent's difficulty
|
||||||
expected := ethash.CalcDifficulty(chain, header.Time.Uint64(), parent)
|
expected := ethash.CalcDifficulty(chain, header.Time, parent)
|
||||||
|
|
||||||
if expected.Cmp(header.Difficulty) != 0 {
|
if expected.Cmp(header.Difficulty) != 0 {
|
||||||
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
||||||
|
@ -349,7 +344,7 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type
|
||||||
// ) + 2^(periodCount - 2)
|
// ) + 2^(periodCount - 2)
|
||||||
|
|
||||||
bigTime := new(big.Int).SetUint64(time)
|
bigTime := new(big.Int).SetUint64(time)
|
||||||
bigParentTime := new(big.Int).Set(parent.Time)
|
bigParentTime := new(big.Int).SetUint64(parent.Time)
|
||||||
|
|
||||||
// holds intermediate values to make the algo easier to read & audit
|
// holds intermediate values to make the algo easier to read & audit
|
||||||
x := new(big.Int)
|
x := new(big.Int)
|
||||||
|
@ -408,7 +403,7 @@ func calcDifficultyHomestead(time uint64, parent *types.Header) *big.Int {
|
||||||
// ) + 2^(periodCount - 2)
|
// ) + 2^(periodCount - 2)
|
||||||
|
|
||||||
bigTime := new(big.Int).SetUint64(time)
|
bigTime := new(big.Int).SetUint64(time)
|
||||||
bigParentTime := new(big.Int).Set(parent.Time)
|
bigParentTime := new(big.Int).SetUint64(parent.Time)
|
||||||
|
|
||||||
// holds intermediate values to make the algo easier to read & audit
|
// holds intermediate values to make the algo easier to read & audit
|
||||||
x := new(big.Int)
|
x := new(big.Int)
|
||||||
|
@ -456,7 +451,7 @@ func calcDifficultyFrontier(time uint64, parent *types.Header) *big.Int {
|
||||||
bigParentTime := new(big.Int)
|
bigParentTime := new(big.Int)
|
||||||
|
|
||||||
bigTime.SetUint64(time)
|
bigTime.SetUint64(time)
|
||||||
bigParentTime.Set(parent.Time)
|
bigParentTime.SetUint64(parent.Time)
|
||||||
|
|
||||||
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
|
||||||
diff.Add(parent.Difficulty, adjust)
|
diff.Add(parent.Difficulty, adjust)
|
||||||
|
@ -558,7 +553,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header)
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
header.Difficulty = ethash.CalcDifficulty(chain, header.Time.Uint64(), parent)
|
header.Difficulty = ethash.CalcDifficulty(chain, header.Time, parent)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func TestCalcDifficulty(t *testing.T) {
|
||||||
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
|
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
|
||||||
diff := CalcDifficulty(config, test.CurrentTimestamp, &types.Header{
|
diff := CalcDifficulty(config, test.CurrentTimestamp, &types.Header{
|
||||||
Number: number,
|
Number: number,
|
||||||
Time: new(big.Int).SetUint64(test.ParentTimestamp),
|
Time: test.ParentTimestamp,
|
||||||
Difficulty: test.ParentDifficulty,
|
Difficulty: test.ParentDifficulty,
|
||||||
})
|
})
|
||||||
if diff.Cmp(test.CurrentDifficulty) != 0 {
|
if diff.Cmp(test.CurrentDifficulty) != 0 {
|
||||||
|
|
|
@ -288,9 +288,9 @@ func (bc *BlockChain) loadLastState() error {
|
||||||
blockTd := bc.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
blockTd := bc.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
||||||
fastTd := bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64())
|
fastTd := bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64())
|
||||||
|
|
||||||
log.Info("Loaded most recent local header", "number", currentHeader.Number, "hash", currentHeader.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(currentHeader.Time.Int64(), 0)))
|
log.Info("Loaded most recent local header", "number", currentHeader.Number, "hash", currentHeader.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(int64(currentHeader.Time), 0)))
|
||||||
log.Info("Loaded most recent local full block", "number", currentBlock.Number(), "hash", currentBlock.Hash(), "td", blockTd, "age", common.PrettyAge(time.Unix(currentBlock.Time().Int64(), 0)))
|
log.Info("Loaded most recent local full block", "number", currentBlock.Number(), "hash", currentBlock.Hash(), "td", blockTd, "age", common.PrettyAge(time.Unix(int64(currentBlock.Time()), 0)))
|
||||||
log.Info("Loaded most recent local fast block", "number", currentFastBlock.Number(), "hash", currentFastBlock.Hash(), "td", fastTd, "age", common.PrettyAge(time.Unix(currentFastBlock.Time().Int64(), 0)))
|
log.Info("Loaded most recent local fast block", "number", currentFastBlock.Number(), "hash", currentFastBlock.Hash(), "td", fastTd, "age", common.PrettyAge(time.Unix(int64(currentFastBlock.Time()), 0)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -904,7 +904,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
|
|
||||||
context := []interface{}{
|
context := []interface{}{
|
||||||
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
||||||
"number", head.Number(), "hash", head.Hash(), "age", common.PrettyAge(time.Unix(head.Time().Int64(), 0)),
|
"number", head.Number(), "hash", head.Hash(), "age", common.PrettyAge(time.Unix(int64(head.Time()), 0)),
|
||||||
"size", common.StorageSize(bytes),
|
"size", common.StorageSize(bytes),
|
||||||
}
|
}
|
||||||
if stats.ignored > 0 {
|
if stats.ignored > 0 {
|
||||||
|
@ -1074,8 +1074,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
// accepted for future processing, and returns an error if the block is too far
|
// accepted for future processing, and returns an error if the block is too far
|
||||||
// ahead and was not added.
|
// ahead and was not added.
|
||||||
func (bc *BlockChain) addFutureBlock(block *types.Block) error {
|
func (bc *BlockChain) addFutureBlock(block *types.Block) error {
|
||||||
max := big.NewInt(time.Now().Unix() + maxTimeFutureBlocks)
|
max := uint64(time.Now().Unix() + maxTimeFutureBlocks)
|
||||||
if block.Time().Cmp(max) > 0 {
|
if block.Time() > max {
|
||||||
return fmt.Errorf("future block timestamp %v > allowed %v", block.Time(), max)
|
return fmt.Errorf("future block timestamp %v > allowed %v", block.Time(), max)
|
||||||
}
|
}
|
||||||
bc.futureBlocks.Add(block.Hash(), block)
|
bc.futureBlocks.Add(block.Hash(), block)
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (st *insertStats) report(chain []*types.Block, index int, dirty common.Stor
|
||||||
"elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed),
|
"elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed),
|
||||||
"number", end.Number(), "hash", end.Hash(),
|
"number", end.Number(), "hash", end.Hash(),
|
||||||
}
|
}
|
||||||
if timestamp := time.Unix(end.Time().Int64(), 0); time.Since(timestamp) > time.Minute {
|
if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute {
|
||||||
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
||||||
}
|
}
|
||||||
context = append(context, []interface{}{"dirty", dirty}...)
|
context = append(context, []interface{}{"dirty", dirty}...)
|
||||||
|
|
|
@ -149,12 +149,12 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
|
||||||
// associated difficulty. It's useful to test scenarios where forking is not
|
// associated difficulty. It's useful to test scenarios where forking is not
|
||||||
// tied to chain length directly.
|
// tied to chain length directly.
|
||||||
func (b *BlockGen) OffsetTime(seconds int64) {
|
func (b *BlockGen) OffsetTime(seconds int64) {
|
||||||
b.header.Time.Add(b.header.Time, big.NewInt(seconds))
|
b.header.Time += uint64(seconds)
|
||||||
if b.header.Time.Cmp(b.parent.Header().Time) <= 0 {
|
if b.header.Time <= b.parent.Header().Time {
|
||||||
panic("block time out of range")
|
panic("block time out of range")
|
||||||
}
|
}
|
||||||
chainreader := &fakeChainReader{config: b.config}
|
chainreader := &fakeChainReader{config: b.config}
|
||||||
b.header.Difficulty = b.engine.CalcDifficulty(chainreader, b.header.Time.Uint64(), b.parent.Header())
|
b.header.Difficulty = b.engine.CalcDifficulty(chainreader, b.header.Time, b.parent.Header())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateChain creates a chain of n blocks. The first block's
|
// GenerateChain creates a chain of n blocks. The first block's
|
||||||
|
@ -225,20 +225,20 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header {
|
func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.StateDB, engine consensus.Engine) *types.Header {
|
||||||
var time *big.Int
|
var time uint64
|
||||||
if parent.Time() == nil {
|
if parent.Time() == 0 {
|
||||||
time = big.NewInt(10)
|
time = 10
|
||||||
} else {
|
} else {
|
||||||
time = new(big.Int).Add(parent.Time(), big.NewInt(10)) // block time is fixed at 10 seconds
|
time = parent.Time() + 10 // block time is fixed at 10 seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.Header{
|
return &types.Header{
|
||||||
Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())),
|
Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())),
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Coinbase: parent.Coinbase(),
|
Coinbase: parent.Coinbase(),
|
||||||
Difficulty: engine.CalcDifficulty(chain, time.Uint64(), &types.Header{
|
Difficulty: engine.CalcDifficulty(chain, time, &types.Header{
|
||||||
Number: parent.Number(),
|
Number: parent.Number(),
|
||||||
Time: new(big.Int).Sub(time, big.NewInt(10)),
|
Time: time - 10,
|
||||||
Difficulty: parent.Difficulty(),
|
Difficulty: parent.Difficulty(),
|
||||||
UncleHash: parent.UncleHash(),
|
UncleHash: parent.UncleHash(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -51,7 +51,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author
|
||||||
Origin: msg.From(),
|
Origin: msg.From(),
|
||||||
Coinbase: beneficiary,
|
Coinbase: beneficiary,
|
||||||
BlockNumber: new(big.Int).Set(header.Number),
|
BlockNumber: new(big.Int).Set(header.Number),
|
||||||
Time: new(big.Int).Set(header.Time),
|
Time: new(big.Int).SetUint64(header.Time),
|
||||||
Difficulty: new(big.Int).Set(header.Difficulty),
|
Difficulty: new(big.Int).Set(header.Difficulty),
|
||||||
GasLimit: header.GasLimit,
|
GasLimit: header.GasLimit,
|
||||||
GasPrice: new(big.Int).Set(msg.GasPrice()),
|
GasPrice: new(big.Int).Set(msg.GasPrice()),
|
||||||
|
|
|
@ -243,7 +243,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
|
||||||
head := &types.Header{
|
head := &types.Header{
|
||||||
Number: new(big.Int).SetUint64(g.Number),
|
Number: new(big.Int).SetUint64(g.Number),
|
||||||
Nonce: types.EncodeNonce(g.Nonce),
|
Nonce: types.EncodeNonce(g.Nonce),
|
||||||
Time: new(big.Int).SetUint64(g.Timestamp),
|
Time: g.Timestamp,
|
||||||
ParentHash: g.ParentHash,
|
ParentHash: g.ParentHash,
|
||||||
Extra: g.ExtraData,
|
Extra: g.ExtraData,
|
||||||
GasLimit: g.GasLimit,
|
GasLimit: g.GasLimit,
|
||||||
|
|
|
@ -290,7 +290,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
|
||||||
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
||||||
"number", last.Number, "hash", last.Hash(),
|
"number", last.Number, "hash", last.Hash(),
|
||||||
}
|
}
|
||||||
if timestamp := time.Unix(last.Time.Int64(), 0); time.Since(timestamp) > time.Minute {
|
if timestamp := time.Unix(int64(last.Time), 0); time.Since(timestamp) > time.Minute {
|
||||||
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
||||||
}
|
}
|
||||||
if stats.ignored > 0 {
|
if stats.ignored > 0 {
|
||||||
|
|
|
@ -79,7 +79,7 @@ type Header struct {
|
||||||
Number *big.Int `json:"number" gencodec:"required"`
|
Number *big.Int `json:"number" gencodec:"required"`
|
||||||
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
||||||
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
Time *big.Int `json:"timestamp" gencodec:"required"`
|
Time uint64 `json:"timestamp" gencodec:"required"`
|
||||||
Extra []byte `json:"extraData" gencodec:"required"`
|
Extra []byte `json:"extraData" gencodec:"required"`
|
||||||
MixDigest common.Hash `json:"mixHash"`
|
MixDigest common.Hash `json:"mixHash"`
|
||||||
Nonce BlockNonce `json:"nonce"`
|
Nonce BlockNonce `json:"nonce"`
|
||||||
|
@ -91,7 +91,7 @@ type headerMarshaling struct {
|
||||||
Number *hexutil.Big
|
Number *hexutil.Big
|
||||||
GasLimit hexutil.Uint64
|
GasLimit hexutil.Uint64
|
||||||
GasUsed hexutil.Uint64
|
GasUsed hexutil.Uint64
|
||||||
Time *hexutil.Big
|
Time hexutil.Uint64
|
||||||
Extra hexutil.Bytes
|
Extra hexutil.Bytes
|
||||||
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
|
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size())
|
||||||
// Size returns the approximate memory used by all internal contents. It is used
|
// Size returns the approximate memory used by all internal contents. It is used
|
||||||
// to approximate and limit the memory consumption of various caches.
|
// to approximate and limit the memory consumption of various caches.
|
||||||
func (h *Header) Size() common.StorageSize {
|
func (h *Header) Size() common.StorageSize {
|
||||||
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+h.Time.BitLen())/8)
|
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rlpHash(x interface{}) (h common.Hash) {
|
func rlpHash(x interface{}) (h common.Hash) {
|
||||||
|
@ -223,9 +223,6 @@ func NewBlockWithHeader(header *Header) *Block {
|
||||||
// modifying a header variable.
|
// modifying a header variable.
|
||||||
func CopyHeader(h *Header) *Header {
|
func CopyHeader(h *Header) *Header {
|
||||||
cpy := *h
|
cpy := *h
|
||||||
if cpy.Time = new(big.Int); h.Time != nil {
|
|
||||||
cpy.Time.Set(h.Time)
|
|
||||||
}
|
|
||||||
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
|
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
|
||||||
cpy.Difficulty.Set(h.Difficulty)
|
cpy.Difficulty.Set(h.Difficulty)
|
||||||
}
|
}
|
||||||
|
@ -288,7 +285,7 @@ func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number)
|
||||||
func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
|
func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
|
||||||
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
||||||
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
||||||
func (b *Block) Time() *big.Int { return new(big.Int).Set(b.header.Time) }
|
func (b *Block) Time() uint64 { return b.header.Time }
|
||||||
|
|
||||||
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
||||||
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestBlockEncoding(t *testing.T) {
|
||||||
check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"))
|
check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"))
|
||||||
check("Hash", block.Hash(), common.HexToHash("0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"))
|
check("Hash", block.Hash(), common.HexToHash("0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"))
|
||||||
check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4))
|
check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4))
|
||||||
check("Time", block.Time(), big.NewInt(1426516743))
|
check("Time", block.Time(), uint64(1426516743))
|
||||||
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
|
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
|
||||||
|
|
||||||
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
|
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil)
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (h Header) MarshalJSON() ([]byte, error) {
|
||||||
Number *hexutil.Big `json:"number" gencodec:"required"`
|
Number *hexutil.Big `json:"number" gencodec:"required"`
|
||||||
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
||||||
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
Time *hexutil.Big `json:"timestamp" gencodec:"required"`
|
Time hexutil.Uint64 `json:"timestamp" gencodec:"required"`
|
||||||
Extra hexutil.Bytes `json:"extraData" gencodec:"required"`
|
Extra hexutil.Bytes `json:"extraData" gencodec:"required"`
|
||||||
MixDigest common.Hash `json:"mixHash"`
|
MixDigest common.Hash `json:"mixHash"`
|
||||||
Nonce BlockNonce `json:"nonce"`
|
Nonce BlockNonce `json:"nonce"`
|
||||||
|
@ -45,7 +45,7 @@ func (h Header) MarshalJSON() ([]byte, error) {
|
||||||
enc.Number = (*hexutil.Big)(h.Number)
|
enc.Number = (*hexutil.Big)(h.Number)
|
||||||
enc.GasLimit = hexutil.Uint64(h.GasLimit)
|
enc.GasLimit = hexutil.Uint64(h.GasLimit)
|
||||||
enc.GasUsed = hexutil.Uint64(h.GasUsed)
|
enc.GasUsed = hexutil.Uint64(h.GasUsed)
|
||||||
enc.Time = (*hexutil.Big)(h.Time)
|
enc.Time = hexutil.Uint64(h.Time)
|
||||||
enc.Extra = h.Extra
|
enc.Extra = h.Extra
|
||||||
enc.MixDigest = h.MixDigest
|
enc.MixDigest = h.MixDigest
|
||||||
enc.Nonce = h.Nonce
|
enc.Nonce = h.Nonce
|
||||||
|
@ -67,7 +67,7 @@ func (h *Header) UnmarshalJSON(input []byte) error {
|
||||||
Number *hexutil.Big `json:"number" gencodec:"required"`
|
Number *hexutil.Big `json:"number" gencodec:"required"`
|
||||||
GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"`
|
||||||
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
Time *hexutil.Big `json:"timestamp" gencodec:"required"`
|
Time *hexutil.Uint64 `json:"timestamp" gencodec:"required"`
|
||||||
Extra *hexutil.Bytes `json:"extraData" gencodec:"required"`
|
Extra *hexutil.Bytes `json:"extraData" gencodec:"required"`
|
||||||
MixDigest *common.Hash `json:"mixHash"`
|
MixDigest *common.Hash `json:"mixHash"`
|
||||||
Nonce *BlockNonce `json:"nonce"`
|
Nonce *BlockNonce `json:"nonce"`
|
||||||
|
@ -123,7 +123,7 @@ func (h *Header) UnmarshalJSON(input []byte) error {
|
||||||
if dec.Time == nil {
|
if dec.Time == nil {
|
||||||
return errors.New("missing required field 'timestamp' for Header")
|
return errors.New("missing required field 'timestamp' for Header")
|
||||||
}
|
}
|
||||||
h.Time = (*big.Int)(dec.Time)
|
h.Time = uint64(*dec.Time)
|
||||||
if dec.Extra == nil {
|
if dec.Extra == nil {
|
||||||
return errors.New("missing required field 'extraData' for Header")
|
return errors.New("missing required field 'extraData' for Header")
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,7 +557,7 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
|
||||||
Number: header.Number,
|
Number: header.Number,
|
||||||
Hash: header.Hash(),
|
Hash: header.Hash(),
|
||||||
ParentHash: header.ParentHash,
|
ParentHash: header.ParentHash,
|
||||||
Timestamp: header.Time,
|
Timestamp: new(big.Int).SetUint64(header.Time),
|
||||||
Miner: author,
|
Miner: author,
|
||||||
GasUsed: header.GasUsed,
|
GasUsed: header.GasUsed,
|
||||||
GasLimit: header.GasLimit,
|
GasLimit: header.GasLimit,
|
||||||
|
|
|
@ -512,12 +512,12 @@ func (b *Block) Difficulty(ctx context.Context) (hexutil.Big, error) {
|
||||||
return hexutil.Big(*header.Difficulty), nil
|
return hexutil.Big(*header.Difficulty), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) Timestamp(ctx context.Context) (hexutil.Big, error) {
|
func (b *Block) Timestamp(ctx context.Context) (hexutil.Uint64, error) {
|
||||||
header, err := b.resolveHeader(ctx)
|
header, err := b.resolveHeader(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return hexutil.Big{}, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return hexutil.Big(*header.Time), nil
|
return hexutil.Uint64(header.Time), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) Nonce(ctx context.Context) (hexutil.Bytes, error) {
|
func (b *Block) Nonce(ctx context.Context) (hexutil.Bytes, error) {
|
||||||
|
|
|
@ -165,7 +165,7 @@ const schema string = `
|
||||||
# GasUsed is the amount of gas that was used executing transactions in this block.
|
# GasUsed is the amount of gas that was used executing transactions in this block.
|
||||||
gasUsed: Long!
|
gasUsed: Long!
|
||||||
# Timestamp is the unix timestamp at which this block was mined.
|
# Timestamp is the unix timestamp at which this block was mined.
|
||||||
timestamp: BigInt!
|
timestamp: Long!
|
||||||
# LogsBloom is a bloom filter that can be used to check if a block may
|
# LogsBloom is a bloom filter that can be used to check if a block may
|
||||||
# contain log entries matching a filter.
|
# contain log entries matching a filter.
|
||||||
logsBloom: Bytes!
|
logsBloom: Bytes!
|
||||||
|
|
|
@ -883,7 +883,7 @@ func RPCMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]inter
|
||||||
"size": hexutil.Uint64(b.Size()),
|
"size": hexutil.Uint64(b.Size()),
|
||||||
"gasLimit": hexutil.Uint64(head.GasLimit),
|
"gasLimit": hexutil.Uint64(head.GasLimit),
|
||||||
"gasUsed": hexutil.Uint64(head.GasUsed),
|
"gasUsed": hexutil.Uint64(head.GasUsed),
|
||||||
"timestamp": (*hexutil.Big)(head.Time),
|
"timestamp": hexutil.Uint64(head.Time),
|
||||||
"transactionsRoot": head.TxHash,
|
"transactionsRoot": head.TxHash,
|
||||||
"receiptsRoot": head.ReceiptHash,
|
"receiptsRoot": head.ReceiptHash,
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ func (lc *LightChain) loadLastState() error {
|
||||||
// Issue a status log and return
|
// Issue a status log and return
|
||||||
header := lc.hc.CurrentHeader()
|
header := lc.hc.CurrentHeader()
|
||||||
headerTd := lc.GetTd(header.Hash(), header.Number.Uint64())
|
headerTd := lc.GetTd(header.Hash(), header.Number.Uint64())
|
||||||
log.Info("Loaded most recent local header", "number", header.Number, "hash", header.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(header.Time.Int64(), 0)))
|
log.Info("Loaded most recent local header", "number", header.Number, "hash", header.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(int64(header.Time), 0)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ func (lc *LightChain) SyncCht(ctx context.Context) bool {
|
||||||
|
|
||||||
// Ensure the chain didn't move past the latest block while retrieving it
|
// Ensure the chain didn't move past the latest block while retrieving it
|
||||||
if lc.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
if lc.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
||||||
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash(), "age", common.PrettyAge(time.Unix(header.Time.Int64(), 0)))
|
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash(), "age", common.PrettyAge(time.Unix(int64(header.Time), 0)))
|
||||||
lc.hc.SetCurrentHeader(header)
|
lc.hc.SetCurrentHeader(header)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -828,8 +828,8 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
||||||
tstart := time.Now()
|
tstart := time.Now()
|
||||||
parent := w.chain.CurrentBlock()
|
parent := w.chain.CurrentBlock()
|
||||||
|
|
||||||
if parent.Time().Cmp(new(big.Int).SetInt64(timestamp)) >= 0 {
|
if parent.Time() >= uint64(timestamp) {
|
||||||
timestamp = parent.Time().Int64() + 1
|
timestamp = int64(parent.Time() + 1)
|
||||||
}
|
}
|
||||||
// this will ensure we're not going off too far in the future
|
// this will ensure we're not going off too far in the future
|
||||||
if now := time.Now().Unix(); timestamp > now+1 {
|
if now := time.Now().Unix(); timestamp > now+1 {
|
||||||
|
@ -844,7 +844,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
||||||
Number: num.Add(num, common.Big1),
|
Number: num.Add(num, common.Big1),
|
||||||
GasLimit: core.CalcGasLimit(parent, w.gasFloor, w.gasCeil),
|
GasLimit: core.CalcGasLimit(parent, w.gasFloor, w.gasCeil),
|
||||||
Extra: w.extra,
|
Extra: w.extra,
|
||||||
Time: big.NewInt(timestamp),
|
Time: uint64(timestamp),
|
||||||
}
|
}
|
||||||
// Only set the coinbase if our consensus engine is running (avoid spurious block rewards)
|
// Only set the coinbase if our consensus engine is running (avoid spurious block rewards)
|
||||||
if w.isRunning() {
|
if w.isRunning() {
|
||||||
|
|
|
@ -109,7 +109,7 @@ func (h *Header) GetDifficulty() *BigInt { return &BigInt{h.header.Difficulty} }
|
||||||
func (h *Header) GetNumber() int64 { return h.header.Number.Int64() }
|
func (h *Header) GetNumber() int64 { return h.header.Number.Int64() }
|
||||||
func (h *Header) GetGasLimit() int64 { return int64(h.header.GasLimit) }
|
func (h *Header) GetGasLimit() int64 { return int64(h.header.GasLimit) }
|
||||||
func (h *Header) GetGasUsed() int64 { return int64(h.header.GasUsed) }
|
func (h *Header) GetGasUsed() int64 { return int64(h.header.GasUsed) }
|
||||||
func (h *Header) GetTime() int64 { return h.header.Time.Int64() }
|
func (h *Header) GetTime() int64 { return int64(h.header.Time) }
|
||||||
func (h *Header) GetExtra() []byte { return h.header.Extra }
|
func (h *Header) GetExtra() []byte { return h.header.Extra }
|
||||||
func (h *Header) GetMixDigest() *Hash { return &Hash{h.header.MixDigest} }
|
func (h *Header) GetMixDigest() *Hash { return &Hash{h.header.MixDigest} }
|
||||||
func (h *Header) GetNonce() *Nonce { return &Nonce{h.header.Nonce} }
|
func (h *Header) GetNonce() *Nonce { return &Nonce{h.header.Nonce} }
|
||||||
|
@ -180,7 +180,7 @@ func (b *Block) GetDifficulty() *BigInt { return &BigInt{b.block.Difficu
|
||||||
func (b *Block) GetNumber() int64 { return b.block.Number().Int64() }
|
func (b *Block) GetNumber() int64 { return b.block.Number().Int64() }
|
||||||
func (b *Block) GetGasLimit() int64 { return int64(b.block.GasLimit()) }
|
func (b *Block) GetGasLimit() int64 { return int64(b.block.GasLimit()) }
|
||||||
func (b *Block) GetGasUsed() int64 { return int64(b.block.GasUsed()) }
|
func (b *Block) GetGasUsed() int64 { return int64(b.block.GasUsed()) }
|
||||||
func (b *Block) GetTime() int64 { return b.block.Time().Int64() }
|
func (b *Block) GetTime() int64 { return int64(b.block.Time()) }
|
||||||
func (b *Block) GetExtra() []byte { return b.block.Extra() }
|
func (b *Block) GetExtra() []byte { return b.block.Extra() }
|
||||||
func (b *Block) GetMixDigest() *Hash { return &Hash{b.block.MixDigest()} }
|
func (b *Block) GetMixDigest() *Hash { return &Hash{b.block.MixDigest()} }
|
||||||
func (b *Block) GetNonce() int64 { return int64(b.block.Nonce()) }
|
func (b *Block) GetNonce() int64 { return int64(b.block.Nonce()) }
|
||||||
|
|
|
@ -82,7 +82,7 @@ type btHeader struct {
|
||||||
Difficulty *big.Int
|
Difficulty *big.Int
|
||||||
GasLimit uint64
|
GasLimit uint64
|
||||||
GasUsed uint64
|
GasUsed uint64
|
||||||
Timestamp *big.Int
|
Timestamp uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type btHeaderMarshaling struct {
|
type btHeaderMarshaling struct {
|
||||||
|
@ -91,7 +91,7 @@ type btHeaderMarshaling struct {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit math.HexOrDecimal64
|
GasLimit math.HexOrDecimal64
|
||||||
GasUsed math.HexOrDecimal64
|
GasUsed math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) Run() error {
|
func (t *BlockTest) Run() error {
|
||||||
|
@ -146,7 +146,7 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
|
||||||
return &core.Genesis{
|
return &core.Genesis{
|
||||||
Config: config,
|
Config: config,
|
||||||
Nonce: t.json.Genesis.Nonce.Uint64(),
|
Nonce: t.json.Genesis.Nonce.Uint64(),
|
||||||
Timestamp: t.json.Genesis.Timestamp.Uint64(),
|
Timestamp: t.json.Genesis.Timestamp,
|
||||||
ParentHash: t.json.Genesis.ParentHash,
|
ParentHash: t.json.Genesis.ParentHash,
|
||||||
ExtraData: t.json.Genesis.ExtraData,
|
ExtraData: t.json.Genesis.ExtraData,
|
||||||
GasLimit: t.json.Genesis.GasLimit,
|
GasLimit: t.json.Genesis.GasLimit,
|
||||||
|
@ -248,7 +248,7 @@ func validateHeader(h *btHeader, h2 *types.Header) error {
|
||||||
if h.GasUsed != h2.GasUsed {
|
if h.GasUsed != h2.GasUsed {
|
||||||
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
||||||
}
|
}
|
||||||
if h.Timestamp.Cmp(h2.Time) != 0 {
|
if h.Timestamp != h2.Time {
|
||||||
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -30,18 +30,18 @@ import (
|
||||||
//go:generate gencodec -type DifficultyTest -field-override difficultyTestMarshaling -out gen_difficultytest.go
|
//go:generate gencodec -type DifficultyTest -field-override difficultyTestMarshaling -out gen_difficultytest.go
|
||||||
|
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *big.Int `json:"parentTimestamp"`
|
ParentTimestamp uint64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *big.Int `json:"parentDifficulty"`
|
ParentDifficulty *big.Int `json:"parentDifficulty"`
|
||||||
UncleHash common.Hash `json:"parentUncles"`
|
UncleHash common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *big.Int `json:"currentTimestamp"`
|
CurrentTimestamp uint64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber uint64 `json:"currentBlockNumber"`
|
CurrentBlockNumber uint64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *big.Int `json:"currentDifficulty"`
|
CurrentDifficulty *big.Int `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type difficultyTestMarshaling struct {
|
type difficultyTestMarshaling struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256
|
ParentTimestamp math.HexOrDecimal64
|
||||||
ParentDifficulty *math.HexOrDecimal256
|
ParentDifficulty *math.HexOrDecimal256
|
||||||
CurrentTimestamp *math.HexOrDecimal256
|
CurrentTimestamp math.HexOrDecimal64
|
||||||
CurrentDifficulty *math.HexOrDecimal256
|
CurrentDifficulty *math.HexOrDecimal256
|
||||||
UncleHash common.Hash
|
UncleHash common.Hash
|
||||||
CurrentBlockNumber math.HexOrDecimal64
|
CurrentBlockNumber math.HexOrDecimal64
|
||||||
|
@ -56,7 +56,7 @@ func (test *DifficultyTest) Run(config *params.ChainConfig) error {
|
||||||
UncleHash: test.UncleHash,
|
UncleHash: test.UncleHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := ethash.CalcDifficulty(config, test.CurrentTimestamp.Uint64(), parent)
|
actual := ethash.CalcDifficulty(config, test.CurrentTimestamp, parent)
|
||||||
exp := test.CurrentDifficulty
|
exp := test.CurrentDifficulty
|
||||||
|
|
||||||
if actual.Cmp(exp) != 0 {
|
if actual.Cmp(exp) != 0 {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
var _ = (*btHeaderMarshaling)(nil)
|
var _ = (*btHeaderMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (b btHeader) MarshalJSON() ([]byte, error) {
|
func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
type btHeader struct {
|
type btHeader struct {
|
||||||
Bloom types.Bloom
|
Bloom types.Bloom
|
||||||
|
@ -31,7 +32,7 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit math.HexOrDecimal64
|
GasLimit math.HexOrDecimal64
|
||||||
GasUsed math.HexOrDecimal64
|
GasUsed math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
var enc btHeader
|
var enc btHeader
|
||||||
enc.Bloom = b.Bloom
|
enc.Bloom = b.Bloom
|
||||||
|
@ -49,10 +50,11 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty)
|
enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty)
|
||||||
enc.GasLimit = math.HexOrDecimal64(b.GasLimit)
|
enc.GasLimit = math.HexOrDecimal64(b.GasLimit)
|
||||||
enc.GasUsed = math.HexOrDecimal64(b.GasUsed)
|
enc.GasUsed = math.HexOrDecimal64(b.GasUsed)
|
||||||
enc.Timestamp = (*math.HexOrDecimal256)(b.Timestamp)
|
enc.Timestamp = math.HexOrDecimal64(b.Timestamp)
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (b *btHeader) UnmarshalJSON(input []byte) error {
|
func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
type btHeader struct {
|
type btHeader struct {
|
||||||
Bloom *types.Bloom
|
Bloom *types.Bloom
|
||||||
|
@ -70,7 +72,7 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit *math.HexOrDecimal64
|
GasLimit *math.HexOrDecimal64
|
||||||
GasUsed *math.HexOrDecimal64
|
GasUsed *math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp *math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
var dec btHeader
|
var dec btHeader
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
@ -122,7 +124,7 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
b.GasUsed = uint64(*dec.GasUsed)
|
b.GasUsed = uint64(*dec.GasUsed)
|
||||||
}
|
}
|
||||||
if dec.Timestamp != nil {
|
if dec.Timestamp != nil {
|
||||||
b.Timestamp = (*big.Int)(dec.Timestamp)
|
b.Timestamp = uint64(*dec.Timestamp)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,31 +12,33 @@ import (
|
||||||
|
|
||||||
var _ = (*difficultyTestMarshaling)(nil)
|
var _ = (*difficultyTestMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (d DifficultyTest) MarshalJSON() ([]byte, error) {
|
func (d DifficultyTest) MarshalJSON() ([]byte, error) {
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256 `json:"parentTimestamp"`
|
ParentTimestamp math.HexOrDecimal64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
||||||
UncleHash common.Hash `json:"parentUncles"`
|
UncleHash common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *math.HexOrDecimal256 `json:"currentTimestamp"`
|
CurrentTimestamp math.HexOrDecimal64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber math.HexOrDecimal64 `json:"currentBlockNumber"`
|
CurrentBlockNumber math.HexOrDecimal64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
var enc DifficultyTest
|
var enc DifficultyTest
|
||||||
enc.ParentTimestamp = (*math.HexOrDecimal256)(d.ParentTimestamp)
|
enc.ParentTimestamp = math.HexOrDecimal64(d.ParentTimestamp)
|
||||||
enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
|
enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
|
||||||
enc.UncleHash = d.UncleHash
|
enc.UncleHash = d.UncleHash
|
||||||
enc.CurrentTimestamp = (*math.HexOrDecimal256)(d.CurrentTimestamp)
|
enc.CurrentTimestamp = math.HexOrDecimal64(d.CurrentTimestamp)
|
||||||
enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
|
enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
|
||||||
enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
|
enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256 `json:"parentTimestamp"`
|
ParentTimestamp *math.HexOrDecimal64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
||||||
UncleHash *common.Hash `json:"parentUncles"`
|
UncleHash *common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *math.HexOrDecimal256 `json:"currentTimestamp"`
|
CurrentTimestamp *math.HexOrDecimal64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber *math.HexOrDecimal64 `json:"currentBlockNumber"`
|
CurrentBlockNumber *math.HexOrDecimal64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
|
@ -45,7 +47,7 @@ func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if dec.ParentTimestamp != nil {
|
if dec.ParentTimestamp != nil {
|
||||||
d.ParentTimestamp = (*big.Int)(dec.ParentTimestamp)
|
d.ParentTimestamp = uint64(*dec.ParentTimestamp)
|
||||||
}
|
}
|
||||||
if dec.ParentDifficulty != nil {
|
if dec.ParentDifficulty != nil {
|
||||||
d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
|
d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
|
||||||
|
@ -54,7 +56,7 @@ func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
d.UncleHash = *dec.UncleHash
|
d.UncleHash = *dec.UncleHash
|
||||||
}
|
}
|
||||||
if dec.CurrentTimestamp != nil {
|
if dec.CurrentTimestamp != nil {
|
||||||
d.CurrentTimestamp = (*big.Int)(dec.CurrentTimestamp)
|
d.CurrentTimestamp = uint64(*dec.CurrentTimestamp)
|
||||||
}
|
}
|
||||||
if dec.CurrentBlockNumber != nil {
|
if dec.CurrentBlockNumber != nil {
|
||||||
d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
|
d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
|
||||||
|
|
Loading…
Reference in New Issue