Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(job): boost block weight when too low #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions txstratum/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@

from hathorlib import BaseTransaction, Block
from hathorlib.scripts import create_output_script
from structlog import get_logger

import txstratum.time
from txstratum.utils import tx_or_block_from_bytes

if TYPE_CHECKING:
from asyncio import TimerHandle

logger = get_logger()


# XXX: This serves to artificially boost the weight until MIN_WEIGHT_EXTRA is reached, boosting the weight is useful
# for making it harder for cpuminers to flood the network in case something goes wrong, it also serves to force a
# higher weight in case the weight is too small to meaningfully increase the block score (in the future this issue
# will probably have been fixed, so it won't matter much). The particular values bellow assume a hashrate of at
# least .5GH/s is being used on the tx-mining-service, this is 5% of the mininmum hashrate a USB GekkoScience ASIC
# can do, and about what 2 GPUs on AWS can do. The boosting mechanism is to basically add WEIGHT_EXTRA_ADD capping
# it to MIN_WEIGHT_EXTRA (examples: weight=21.0 -> weight=25.0, weight=30.0 -> weight=34.0, weight=31.0 ->
# weight=34.0, weight=34.0 -> weight=34.0, weight=35.0 -> weight=35.0)
MIN_WEIGHT_EXTRA = 34.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused with this param name at first, to be honest. I was thinking about something like MAX_WEIGHT_TO_ADD_EXTRA. I'm okay to move with the current name as well

Copy link
Member Author

@jansegre jansegre Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the name was chosen poorly. But your suggestion seems a bit convoluted, what about WEIGHT_BOOST_CAP, and WEIGHT_BOOST_BONUS.

WEIGHT_EXTRA_ADD = 4.0


class JobStatus(enum.Enum):
"""Job status."""
Expand Down Expand Up @@ -256,6 +271,13 @@ class MinerBlockJob(MinerJob):
def __init__(self, data: bytes, height: int):
"""Init MinerBlockJob."""
self._block: Block = Block.create_from_struct(data)
cur_weight = self._block.weight
extra_weight = self._block.weight + WEIGHT_EXTRA_ADD
new_weight = (cur_weight if cur_weight > MIN_WEIGHT_EXTRA else
MIN_WEIGHT_EXTRA if extra_weight > MIN_WEIGHT_EXTRA else extra_weight)
if new_weight != self._block.weight:
self._block.weight = new_weight
logger.warn(f'Force weight={new_weight} to avoid insignificant score bump')
self.height: int = height

self.uuid: bytes = uuid.uuid4().bytes
Expand Down