Skip to content

Calling staker.worker_address twice when no worker is bonded returns two different values #2114

@derekpierre

Description

@derekpierre

Describe the Bug
Calling the property staker.worker_address twice on the same staker object when there is no bonded worker returns NO_WORKER_BONDED first, and then returns NULL_ADDRESS for subsequent calls.

To Reproduce
I was attempting to highlight Worker <worker_address> as red in the output of nucypher stake list when no worker is bonded to the staker. To do so I decided to modify the line:

emitter.echo(f"Worker {staker.worker_address} ════")

to instead be

emitter.echo(f"Worker {staker.worker_address} ════", color='red' if (staker.worker_address == NO_WORKER_BONDED) else None)

which did not work. The reason being that the first call to staker.worker_address returns NO_WORKER_BONDED, but a second (or subsequent) call(s) returns NULL_ADDRESS.

Looking at the worker_address function:

    @property
    def worker_address(self) -> str:
        if self.__worker_address:
            # TODO: This is broken for StakeHolder with different stakers - See #1358
            return self.__worker_address
        else:
            worker_address = self.staking_agent.get_worker_from_staker(staker_address=self.checksum_address)
            self.__worker_address = worker_address

        if self.__worker_address == NULL_ADDRESS:
            return NO_WORKER_BONDED.bool_value(False)
        return self.__worker_address

On the second call to this function, self.__worker_address is already set and simply returns its value which is NULL_ADDRESS instead of getting modified to be NO_WORKER_BONDED again.

It should probably be modified to be

    @property
    def worker_address(self) -> str:
        if not self.__worker_address:
            worker_address = self.staking_agent.get_worker_from_staker(staker_address=self.checksum_address)
            self.__worker_address = worker_address

        if self.__worker_address == NULL_ADDRESS:
            return NO_WORKER_BONDED.bool_value(False)
        return self.__worker_address

I didn't want to make the change myself because I am unsure of the repercussions for such a change.

**Traceback or Screenshots (Optional) **
N/A

System (please complete the following information):

  • OS Version: Linux Ubuntu 18.04.4
  • Nucypher Version: master @ 202e502
  • Ethereum Node Version: Geth 1.9.15-stable-0f77f34b

Metadata

Metadata

Labels

Bug 🐛Broken functionalityCLIThis effects the nucypher CLI

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions