Skip to content

Commit

Permalink
Specify location for new blocks to mine, as well as received blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Jan 4, 2024
1 parent 7da6b72 commit 44f6d04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,20 @@
"upstreamCheckInterval": "5s",
"upstream": [
{
"name": "prime",
"context": "prime",
"url": "ws://127.0.0.1:8547",
"timeout": "10s"
},
{
"name": "region",
"context": "region",
"name": "",
"url": "",
"timeout": "10s"
},
{
"name": "zone",
"context": "zone",
"name": "",
"url": "",
"timeout": "10s"
}
],
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ func readConfig(cfg *proxy.Config) {
cfg.Upstream[common.PRIME_CTX].Url = "ws://127.0.0.1:" + returnPortHelper(*primePort)
}
if regionPort != nil && *regionPort != "" {
cfg.Upstream[common.REGION_CTX].Name = *regionPort
cfg.Upstream[common.REGION_CTX].Url = "ws://127.0.0.1:" + returnPortHelper(*regionPort)
}
if zonePort != nil && *zonePort != "" {
cfg.Upstream[common.ZONE_CTX].Name = *zonePort
cfg.Upstream[common.ZONE_CTX].Url = "ws://127.0.0.1:" + returnPortHelper(*zonePort)
}
if *stratumPort != -1 {
Expand Down
6 changes: 3 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (s *ProxyServer) updateBlockTemplate(pendingHeader *types.Header) {

s.blockTemplate.Store(&newTemplate)
s.headerCache.Add(newTemplate.JobID, newTemplate.Header)
log.Printf("New block to mine on %s at height %d", common.OrderToString(common.ZONE_CTX), pendingHeader.NumberArray())
log.Printf("New block to mine on %s at height %d", s.config.Upstream[common.ZONE_CTX].Name, pendingHeader.NumberArray())

difficultyMh := strconv.FormatUint(newTemplate.Header.Difficulty().Uint64() / 1000000, 10)
if len(difficultyMh) >= 3 {
Expand All @@ -334,7 +334,7 @@ func (s *ProxyServer) updateBlockTemplate(pendingHeader *types.Header) {
func (s *ProxyServer) verifyMinedHeader(jobID uint, nonce []byte) (*types.Header, error) {
header, ok := s.headerCache.Get(jobID)
if !ok {
return nil, fmt.Errorf("Unable to find header for that jobID: %d", jobID)
return nil, fmt.Errorf("unable to find header for that jobID: %d", jobID)
}
header = types.CopyHeader(header)

Expand All @@ -347,7 +347,7 @@ func (s *ProxyServer) verifyMinedHeader(jobID uint, nonce []byte) (*types.Header
}

powHash, err := s.engine.VerifySeal(header)
log.Printf("Miner submitted a block. Number: %d. Blockhash: %#x", header.NumberU64(common.ZONE_CTX), header.Hash())
log.Printf("Miner submitted a block. Location: %s. Number: %d. Blockhash: %#x", s.config.Upstream[common.ZONE_CTX].Name, header.NumberU64(common.ZONE_CTX), header.Hash())
if err != nil {
return nil, fmt.Errorf("unable to verify seal of block: %#x. %v", powHash, err)
}
Expand Down

0 comments on commit 44f6d04

Please sign in to comment.