Skip to content

Commit

Permalink
Distinguish insufficient_partials from invalid_partials (Chia-Net…
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP authored Oct 30, 2023
1 parent 8db4860 commit c9f4146
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 49 deletions.
2 changes: 2 additions & 0 deletions chia/farmer/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ async def update_pool_state(self) -> None:
"valid_partials_24h": [],
"invalid_partials_since_start": 0,
"invalid_partials_24h": [],
"insufficient_partials_since_start": 0,
"insufficient_partials_24h": [],
"stale_partials_since_start": 0,
"stale_partials_24h": [],
"missing_partials_since_start": 0,
Expand Down
101 changes: 57 additions & 44 deletions chia/farmer/farmer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def new_proof_of_space(
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"invalid_partials",
"insufficient_partials",
time.time(),
)
self.farmer.state_changed(
Expand Down Expand Up @@ -317,64 +317,77 @@ async def new_proof_of_space(
ssl=ssl_context_for_root(get_mozilla_ca_crt(), log=self.farmer.log),
headers={"User-Agent": f"Chia Blockchain v.{__version__}"},
) as resp:
if resp.ok:
pool_response: Dict[str, Any] = json.loads(await resp.text())
self.farmer.log.info(f"Pool response: {pool_response}")
if "error_code" in pool_response:
self.farmer.log.error(
f"Error in pooling: "
f"{pool_response['error_code'], pool_response['error_message']}"
)

if not resp.ok:
self.farmer.log.error(f"Error sending partial to {pool_url}, {resp.status}")
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"invalid_partials",
time.time(),
)
return

pool_response: Dict[str, Any] = json.loads(await resp.text())
self.farmer.log.info(f"Pool response: {pool_response}")
if "error_code" in pool_response:
self.farmer.log.error(
f"Error in pooling: "
f"{pool_response['error_code'], pool_response['error_message']}"
)

increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"pool_errors",
time.time(),
value=pool_response,
)

if pool_response["error_code"] == PoolErrorCode.TOO_LATE.value:
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"pool_errors",
"stale_partials",
time.time(),
value=pool_response,
)

if pool_response["error_code"] == PoolErrorCode.TOO_LATE.value:
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"stale_partials",
time.time(),
)
else:
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"invalid_partials",
time.time(),
)

if pool_response["error_code"] == PoolErrorCode.PROOF_NOT_GOOD_ENOUGH.value:
self.farmer.log.error(
"Partial not good enough, forcing pool farmer update to "
"get our current difficulty."
)
pool_state_dict["next_farmer_update"] = 0
await self.farmer.update_pool_state()
else:
elif pool_response["error_code"] == PoolErrorCode.PROOF_NOT_GOOD_ENOUGH.value:
self.farmer.log.error(
"Partial not good enough, forcing pool farmer update to "
"get our current difficulty."
)
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"valid_partials",
"insufficient_partials",
time.time(),
)
new_difficulty = pool_response["new_difficulty"]
pool_state_dict["next_farmer_update"] = 0
await self.farmer.update_pool_state()
else:
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"points_acknowledged",
"invalid_partials",
time.time(),
new_difficulty,
new_difficulty,
)
pool_state_dict["current_difficulty"] = new_difficulty
else:
self.farmer.log.error(f"Error sending partial to {pool_url}, {resp.status}")
return

increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"valid_partials",
time.time(),
)
new_difficulty = pool_response["new_difficulty"]
increment_pool_stats(
self.farmer.pool_state,
p2_singleton_puzzle_hash,
"points_acknowledged",
time.time(),
new_difficulty,
new_difficulty,
)
pool_state_dict["current_difficulty"] = new_difficulty
except Exception as e:
self.farmer.log.error(f"Error connecting to pool: {e}")

Expand Down
Loading

0 comments on commit c9f4146

Please sign in to comment.