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

Replace ExecutedAndBlockMessages with individual methods #1040

Merged
merged 11 commits into from
Aug 30, 2022

Conversation

frrist
Copy link
Member

@frrist frrist commented Aug 18, 2022

What

This PR removes the ExecutedAndBlockMessages method and replaces it smaller more specific methods: TipSetMessageReceipts, TipSetBlockMessages, and ComputeGasOutputs.

While implementing, I noticed a few bugs in the now replaced ExecutedAndBlockMessages method, which are tracked in #1045 and #1043 and fixed in this PR. Furthermore, I took the opportunity to address #1041 while implementing TipSetMessageReceipts.

@frrist frrist self-assigned this Aug 19, 2022
@frrist frrist linked an issue Aug 22, 2022 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2022

Codecov Report

Merging #1040 (f3d0d2e) into master (593dad6) will decrease coverage by 0.0%.
The diff coverage is 25.0%.

@@           Coverage Diff            @@
##           master   #1040     +/-   ##
========================================
- Coverage    34.4%   34.4%   -0.1%     
========================================
  Files          44      44             
  Lines        2925    2930      +5     
========================================
  Hits         1008    1008             
- Misses       1821    1826      +5     
  Partials       96      96             

@frrist frrist force-pushed the frrist/message-api branch 3 times, most recently from 24648f0 to 72909f1 Compare August 23, 2022 23:31
@frrist frrist marked this pull request as ready for review August 23, 2022 23:43
@frrist frrist changed the title Frrist/message api Replace ExecutedAndBlockMessages with simpler methods Aug 23, 2022
@frrist frrist changed the title Replace ExecutedAndBlockMessages with simpler methods Replace ExecutedAndBlockMessages with individual methods Aug 23, 2022
return false
}

func (mri *MessageReceiptIterator) Next() (types.ChainMsg, int, *types.MessageReceipt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (mri *MessageReceiptIterator) Next() (types.ChainMsg, int, *types.MessageReceipt) {
func (mri *MessageReceiptIterator) Next() (types.ChainMsg, *types.MessageReceipt) {

is the index necessary as part of the return value? i did a quick scan of where this is being called and only saw it once here.

could the index also be accessed as:

msg, rec := itr.Next()
idx := itr.exeIdx[msg]

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I will comment this, idx is the messages execution index in the tipset - the order the message was executed in relative to other messages in the tipset.

return out, nil
}

// TipSetMessageReceipts returns the blocks and messages in `pts` and their corresponding receipts from `ts` matching block order in tipset (`pts`).
Copy link
Contributor

Choose a reason for hiding this comment

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

What does pts mean? parent tipset?

Copy link
Member Author

Choose a reason for hiding this comment

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

Parent tipset yes. aka ts.Parent()

Copy link
Contributor

@kasteph kasteph left a comment

Choose a reason for hiding this comment

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

I didn't see any glaring logical errors in any of the tasks nor in the TipSetMessageReceipts() function. My previous comments are not blockers.


return data, innerErr
})
func (t *DataSource) ShouldBrunFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (t *DataSource) ShouldBrunFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error) {
func (t *DataSource) ShouldBurnFn(ctx context.Context, ts *types.TipSet) (lens.ShouldBurnFn, error) {

return nil, fmt.Errorf("loading message receipts %w", err)
}
}
// so we only load the receipt array one
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// so we only load the receipt array one
// so we only load the receipt array once

CircSupplyCalc: m.StateManager.GetVMCirculatingSupply,
NetworkVersion: util.DefaultNetwork.Version(ctx, ts.Height()),
BaseFee: ts.Blocks()[0].ParentBaseFee,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the VM very "heavy" in size? Should vmi be memoized within LilyNodeAPI and have the appropriate statetree applied at the time of request within the wrapper?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question. Currently, this method is only called by the GasOuptut task, so until another task needs to call this method we can leave out caching.

}

newBaseFee := store.ComputeNextBaseFee(executed.Blocks()[0].ParentBaseFee, totalUniqGasLimit, len(executed.Blocks()), executed.Height())
baseFeeRat := new(big.Rat).SetFrac(newBaseFee.Int, new(big.Int).SetUint64(build.FilecoinPrecision))
currentBaseFee, err := t.node.ComputeBaseFee(ctx, current)
Copy link
Member Author

Choose a reason for hiding this comment

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

#1045 fixed here, this calls the lotus ComputeBaseFee method directly: https://github.com/filecoin-project/lotus/blob/master/chain/store/basefee.go#L50

GasFeeCap: msg.VMMessage().GasFeeCap.String(),
GasPremium: msg.VMMessage().GasPremium.String(),
GasLimit: msg.VMMessage().GasLimit,
SizeBytes: msg.ChainLength(),
Copy link
Member Author

Choose a reason for hiding this comment

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

}

// TipSetMessageReceipts returns the blocks and messages in `pts` and their corresponding receipts from `ts` matching block order in tipset (`pts`).
func (m *LilyNodeAPI) TipSetMessageReceipts(ctx context.Context, ts, pts *types.TipSet) ([]*lens.BlockMessageReceipts, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I have implemented this method in lotus: filecoin-project/lotus#9186, initial review (walked through with the lotus team together) suggests this is correct - as does the comparison with existing data in the production database. Once filecoin-project/lotus#9186 merges I will replace this with a direct call to the lotus method.

Comment on lines +544 to +549
out.TipsetProcessors[t] = messagetask.NewTask(api)
case tasktype.BlockMessage:
out.TipsetProcessors[t] = bmtask.NewTask(api)
case tasktype.MessageGasEconomy:
out.TipsetProcessors[t] = gasecontask.NewTask(api)

Copy link
Member Author

Choose a reason for hiding this comment

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

These tasks were simplified to require a single tipset to operate, resulting from the removal of ExecutedAndBlockMessages which requires a child and a parent tipset.

return out, nil
}

// TipSetMessageReceipts returns the blocks and messages in `pts` and their corresponding receipts from `ts` matching block order in tipset (`pts`).
Copy link
Member Author

Choose a reason for hiding this comment

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

Parent tipset yes. aka ts.Parent()

return false
}

func (mri *MessageReceiptIterator) Next() (types.ChainMsg, int, *types.MessageReceipt) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I will comment this, idx is the messages execution index in the tipset - the order the message was executed in relative to other messages in the tipset.

CircSupplyCalc: m.StateManager.GetVMCirculatingSupply,
NetworkVersion: util.DefaultNetwork.Version(ctx, ts.Height()),
BaseFee: ts.Blocks()[0].ParentBaseFee,
})
Copy link
Member Author

Choose a reason for hiding this comment

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

Great question. Currently, this method is only called by the GasOuptut task, so until another task needs to call this method we can leave out caching.

@frrist frrist merged commit ab09cca into master Aug 30, 2022
@frrist frrist deleted the frrist/message-api branch August 30, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants