Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/es-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewConfig(ctx *cli.Context, lg log.Logger) (*node.Config, error) {
lg.Info("Read chain ID of EthStorage network", "chainID", chainId)
if minerConfig != nil {
minerConfig.ChainID = chainId
minerConfig.Slot = l1Endpoint.L1BeaconSlotTime
}
archiverConfig := archiver.NewConfig(ctx)
// l2Endpoint, err := NewL2EndpointConfig(ctx, lg)
Expand Down
10 changes: 2 additions & 8 deletions ethstorage/eth/polling_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"golang.org/x/mod/semver"
)

Expand Down Expand Up @@ -195,14 +196,7 @@ func (w *PollingClient) pollHeads() {
func (w *PollingClient) getLatestHeader() (*types.Header, error) {
ctx, cancel := context.WithTimeout(w.ctx, 5*time.Second)
defer cancel()
latest, err := w.BlockNumber(ctx)
if err != nil {
w.lg.Error("Failed to get latest block number", "err", err)
return nil, err
}
// The latest blockhash could be empty
number := new(big.Int).SetUint64(latest - 1)
return w.HeaderByNumber(ctx, number)
return w.HeaderByNumber(ctx, big.NewInt(rpc.LatestBlockNumber.Int64()))
}

func (w *PollingClient) reqPoll() {
Expand Down
3 changes: 1 addition & 2 deletions ethstorage/eth/randao_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func (q *RandaoBlockQuerier) getLatestNumber(ctx context.Context) (*big.Int, err
if err != nil {
return nil, fmt.Errorf("failed to call number() %v", err)
}
// The latest blockhash could be empty
curBlock := new(big.Int).Sub(new(big.Int).SetBytes(ret), common.Big1)
curBlock := new(big.Int).SetBytes(ret)
q.lg.Debug("Got latest block number by Randao querier", "number", curBlock)
return curBlock, nil
}
Expand Down
1 change: 1 addition & 0 deletions ethstorage/miner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
type Config struct {
// es network chain id
ChainID *big.Int
Slot uint64

// contract
RandomChecks uint64
Expand Down
11 changes: 8 additions & 3 deletions ethstorage/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
const (
chainHeadChanSize = 1
taskQueueSize = 1
resultQueueSize = 10
slot = 12 // seconds
miningTransactionTimeout = 50 // seconds

// tx status codes
Expand Down Expand Up @@ -428,6 +426,13 @@ func (w *worker) resultLoop() {
continue
}
w.lg.Info("Mining result loop get result", "shard", result.startShardId, "block", result.blockNumber, "nonce", result.nonce)

// Mining result comes within the same block time window
if tillNextSlot := int64(result.timestamp) + int64(w.config.Slot) - time.Now().Unix(); tillNextSlot > 0 {
// Wait until next block comes to avoid empty blockhash on gas estimation
w.lg.Info("Hold on submitting mining result till block+1", "block", result.blockNumber, "secondsToWait", tillNextSlot)
time.Sleep(time.Duration(tillNextSlot) * time.Second)
}
txHash, err := w.l1API.SubmitMinedResult(
context.Background(),
w.storageMgr.ContractAddress(),
Expand Down Expand Up @@ -633,7 +638,7 @@ func (w *worker) mineTask(t *taskItem) (bool, error) {
w.lg.Debug("Mining task started", "shard", t.shardIdx, "thread", t.thread, "block", t.blockNumber, "nonces", fmt.Sprintf("%d~%d", t.nonceStart, t.nonceEnd))
for w.isRunning() {
// always use new randao to mine for each slot
if time.Since(startTime).Seconds() > slot {
if time.Since(startTime).Seconds() > float64(w.config.Slot) {
if t.thread == 0 {
nonceTriedTotal := (nonce - t.nonceStart) * w.config.ThreadsPerShard
w.lg.Warn("Mining tasks timed out", "shard", t.shardIdx, "block", t.blockNumber,
Expand Down
Loading