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

init #1

Closed
wants to merge 17 commits into from
Closed

init #1

wants to merge 17 commits into from

Conversation

bendanzhentan
Copy link
Contributor

No description provided.

Copy link

@welkin22 welkin22 left a comment

Choose a reason for hiding this comment

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

LGTM

@owen-reorg

This comment was marked as resolved.

core/types.go Outdated Show resolved Hide resolved
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) public payable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The user may compose malicious tx for the bot runner to finalize, and these limitations can't be hardcoded in the contracts. So we should set filter for events to handle:

  • _l2Token in known list
  • _minGasLimit can't be bigger than known value. In practice, we'll set a fixed value in the front end
  • _extraData should be empty

txns from bridge UI will match the filter while custom txn sent directly by users may not.

Copy link
Contributor Author

@bendanzhentan bendanzhentan Nov 23, 2023

Choose a reason for hiding this comment

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

Hi @owen-reorg I have created another PR #8

With #8, I think it can handle malicious cases alraedy.

Then I think this suggesting filter may be not necessary for a malicious withdrawal, since the contract will return a revert error when proving or finalizing. Afterward, we will record the revert-error and skip the reverted withdrawals later.

LogIndex int `gorm:"type:integer;not null;uniqueIndex:idx_l2_contract_events_block_hash_log_index_key,priority:2"`
EventSignature string `gorm:"type:varchar(256);not null"`
Proven bool `gorm:"type:boolean;not null;default:false"`
Finalized bool `gorm:"type:boolean;not null;default:false"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a withdrawal txn is not expected, we may need to ignore it. I suggest to add a field for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another PR has been created to apply this suggestion #8

name = "db_name"

[l1-contracts]
address-manager = "0x1111111111111111111111111111111111111111"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's determined for both testnet and mainnet.

  1. Remove unnecessary configurations.
  2. List both testnet and mainnet configurations here. Use testnet as the default and comment out the mainnet configuration.

return fmt.Errorf("hashMesaageHash err: %v", err)
}

l2OutputIndex, outputProposal, err := b.getL2OutputAfter(l2BlockNumber)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can use the latest L2 block number in L2OutputOracle. Can you please give it a try? If we use an earlier block, the performance of getProof will be worse. Additionally, nodes running in certain modes may remove the early trie data, making it impossible to obtain the proof.

core/processor.go Outdated Show resolved Hide resolved
core/processor.go Outdated Show resolved Hide resolved
b.L1Contracts.OptimismPortalProxy,
b.L1Client,
)
signedTx, err := optimismPortalTransactor.ProveWithdrawalTransaction(
Copy link
Collaborator

Choose a reason for hiding this comment

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

will it dry run before send?
what if the tx fails?
what if the tx pending for a long time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. It will estimate gas before sending. Eth_estimateGas can be considered a dry run.

  2. No retry for tx failures. These unproven withdrawals will be rescanned by the processor goroutine and retried to prove.

  3. As (2) says, I think failed transactions will be retried by the processor goroutine.

I am finding a way to enhance the transaction management, please touch me if you have some ideas.

@owen-reorg

This comment was marked as resolved.

1. contracts: transfer fee via call
2. cmd: git add run.go
3. core: add SignerConfig for signer and gas price
4. core: reduce duplicated code in ProveWithdrawalTransaction and FinalizeWithdrawalTransaction
5. core: fix type definition ContractAddress
6. ci: add workflow build.yaml
@bendanzhentan
Copy link
Contributor Author

There is a lack of main loop logic. Did you forget to submit any files?

Yes, the fun fact is that .gitignore includes cmd/ so that I didn't realize that cmd/bot/run.go didn't include in git.

I make some updates at ddfaf66 according to the below review suggestions:

  1. contracts: transfer fee via call init #1 (comment)
  2. cmd: git add run.go init #1 (comment)
  3. core: add SignerConfig for signer and gas price init #1 (comment)
  4. core: reduce duplicated code in ProveWithdrawalTransaction and FinalizeWithdrawalTransaction init #1 (comment)
  5. core: fix type definition ContractAddress init #1 (comment)
  6. ci: add workflow build.yaml init #1 (comment)

result := db.Order("number desc").Last(&l2ScannedBlock)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
db.Create(&l2ScannedBlock)
Copy link
Collaborator

Choose a reason for hiding this comment

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

shall we set a start number in config instead of start from block #0?

continue
} else if len(unprovens) > 0 {
for _, unproven := range unprovens {
if unproven.BlockTime+cfg.Misc.ProposeTimeWindow < time.Now().Unix() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally too deep nested code is hard to read. I suggest rewrite it by handle earlier with esle condition.

E.g.

if unproven.BlockTime+cfg.Misc.ProposeTimeWindow >= time.Now().Unix() {
    continue
}
original_if_code_block()

Copy link
Contributor Author

@bendanzhentan bendanzhentan Nov 23, 2023

Choose a reason for hiding this comment

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

Another PR has been created to refactor this function, to make it more readable. PTAL #7

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.

3 participants