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

Print scheduledRewards instead of totalEarnings. Closes #255 #259

Merged
merged 5 commits into from
Nov 17, 2023

Conversation

juliangruber
Copy link
Member

Closes #255

Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
ethers 6.8.1 network, filesystem +7 19.2 MB ricmoo

@bajtos
Copy link
Member

bajtos commented Nov 13, 2023

@juliangruber I'd like to discuss the high-level picture first.

(1)
It is possible to use the same wallet address for multiple Station Core instances. However, it's not possible to tell how many rewards were earned by which instance. All we have is the total sum for all Stations using this wallet address.

I expect this is going to create confusion for Station Core users.

For example, if I were running a bunch of Station Core instances, aggregating their metrics and rendering them in a dashboard, I would calculate my expected earnings as sum(scheduledRewards).

How can we clarify what the number in scheduledRewards means? Maybe we can rename it something else, e.g. totalRewardsScheduledForAddress (preferably find a more succinct option).

Either way, it's IMO important to explain this in our docs (the README file?).

(2)
Should we leverage this new metrics produced by Station Core in Station Desktop? We can rework the way how Desktop obtains the "scheduled rewards" value to fetch it from Station Core state instead the RPC API.

The upside is that we avoid duplication.

The downside is a slightly more complex integration and closing the door to move RPC API calls querying on-chain state from main to rendered, which would simplify this part a lot.

@juliangruber
Copy link
Member Author

How can we clarify what the number in scheduledRewards means? Maybe we can rename it something else, e.g. totalRewardsScheduledForAddress (preferably find a more succinct option).

Good call! I agree this would be clearer. What about rewardsScheduledForAddress?

Should we leverage this new metrics produced by Station Core in Station Desktop? We can rework the way how Desktop obtains the "scheduled rewards" value to fetch it from Station Core state instead the RPC API.

I'm in favor of reading this from Station Core, so that we only have this logic in one place.

@juliangruber juliangruber marked this pull request as draft November 13, 2023 16:22
@bajtos
Copy link
Member

bajtos commented Nov 14, 2023

rewardsScheduledForAddress

SGTM!

If we are not going to use this metric in Station Desktop, then does Station Core need to periodically emit it?

An alternative to consider: add a new CLI command to find out what's the current amount.

Comment on lines +49 to +63
const provider = new ethers.JsonRpcProvider(
'https://api.node.glif.io/rpc/v1',
null,
{ batchMaxCount: 1 }
)
const contract = new ethers.Contract(
'0xaaef78eaf86dcf34f275288752e892424dda9341',
JSON.parse(
await fs.readFile(
fileURLToPath(new URL('./abi.json', import.meta.url)),
'utf8'
)
),
provider
)
Copy link
Member

Choose a reason for hiding this comment

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

I find it weird that it's the Zinnia module that handles querying the smart contract for scheduled rewards.

In my mind, this functionality is not specific to Zinnia (or Bacalhau or any other module) and, therefore, it belongs to Station Core itself.

What are the arguments in favour of placing this new logic here?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good question! My initial reasoning was that bacalhau doesn't use this, so it doesn't belong in core, above all modules. And who knows, maybe we will even add another trusted module in the future?

Otoh, it doesn't belong into Zinnia either, because it's the module's decision whether to use Meridian. ethers might even run in Zinnia, since for this we don't need to sign messages - or we could just use the jsonrpc endpoint directly - then we only need fetch. I think for this we need a way for Zinnia modules to log metrics.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Please update our checklist for deploying the new Meridian version to remind us that we need to update this place in Station Core, too?

Copy link
Member Author

Choose a reason for hiding this comment

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

@juliangruber
Copy link
Member Author

If we are not going to use this metric in Station Desktop, then does Station Core need to periodically emit it?

Once core exposes it we can remove this exact logic from Desktop again, so that it only lives in one place. Wdyt?

@juliangruber juliangruber marked this pull request as ready for review November 17, 2023 10:20
@juliangruber
Copy link
Member Author

juliangruber commented Nov 17, 2023

@bajtos hindsight please. I would like to get this out as a UX improvement. I think the interface isn't going to change, only where the code lives - which we can address next week.

@juliangruber juliangruber merged commit e7b13dc into main Nov 17, 2023
16 checks passed
@juliangruber juliangruber deleted the add/scheduled-rewards branch November 17, 2023 10:26
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Let's improve error handling please 👇🏻

lib/zinnia.js Show resolved Hide resolved
@bajtos
Copy link
Member

bajtos commented Nov 22, 2023

If we are not going to use this metric in Station Desktop, then does Station Core need to periodically emit it?

Once core exposes it we can remove this exact logic from Desktop again, so that it only lives in one place. Wdyt?

Initially, I as indifferent:

On one hand, removing the duplication is good.

On the other hand, there is also value in moving all on-chain querying into the Station Desktop front-end so that we don't have to maintain so much Electron IPC stuff.

  • The backend (main) provides a IPC method for obtaining the public address of the built-in wallet
  • The backend also provides addresses of Meridian smart contracts for querying the balances
  • The front-end creates Ethers.js clients for these smart contracts and periodically queries the state

As I wrote this, I realised it may not be feasible to query "scheduled rewards" from the front-end if different modules have different smart contract ABIs and even different methods to query the balance. We may need to move this logic down into each Zinnia module, so that Station does not have any module-specific logic. In that case, it makes a lot of sense that Station Desktop should consume rewardsScheduledForAddress metric provided by Station Core.

So, let's do it!

filecoin-station/desktop#1134

@bajtos
Copy link
Member

bajtos commented Nov 22, 2023

Otoh, it doesn't belong into Zinnia either, because it's the module's decision whether to use Meridian. ethers might even run in Zinnia, since for this we don't need to sign messages - or we could just use the jsonrpc endpoint directly - then we only need fetch. I think for this we need a way for Zinnia modules to log metrics.

Yeah, I agree.

Opened a GH issue to implement this new feature in Zinnia: filecoin-station/zinnia#421

@bajtos
Copy link
Member

bajtos commented Nov 22, 2023

Otoh, it doesn't belong into Zinnia either, because it's the module's decision whether to use Meridian. ethers might even run in Zinnia, since for this we don't need to sign messages - or we could just use the jsonrpc endpoint directly - then we only need fetch. I think for this we need a way for Zinnia modules to log metrics.

Yeah, I agree.

Opened a GH issue to implement this new feature in Zinnia: filecoin-station/zinnia#421

Actually, this requires more work besides Zinnia, I opened a higher-level issue to keep track of all subtasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework total_earnings to scheduled_rewards
2 participants