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

multicall #48

Merged
merged 13 commits into from
Jul 24, 2024
Merged

multicall #48

merged 13 commits into from
Jul 24, 2024

Conversation

dai1975
Copy link
Contributor

@dai1975 dai1975 commented Jun 17, 2024

Send tx by using Multicall3

@dai1975 dai1975 marked this pull request as ready for review June 17, 2024 10:27
@dai1975 dai1975 requested a review from siburu June 17, 2024 10:27
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

@dai1975 I reviewed codes except for relay/ethereum/tx.go and put some comments.
I will review tx.go from now.

pkg/relay/ethereum/chain.go Outdated Show resolved Hide resolved
pkg/relay/ethereum/config.go Outdated Show resolved Hide resolved
pkg/contract/ibchandler/ibchandler.go Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

@dai1975 Sorry for late reply! I put some comments.

pkg/relay/ethereum/tx.go Show resolved Hide resolved
pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
@dai1975
Copy link
Contributor Author

dai1975 commented Jul 17, 2024

rebase.

Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

@dai1975 I'm sorry for late review.
I left some comments.

pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
pkg/relay/ethereum/tx.go Show resolved Hide resolved
Comment on lines 537 to 539
{
logger := &log.RelayLogger{Logger: logger.Logger}

Copy link
Contributor

Choose a reason for hiding this comment

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

After fixing estimateGas as I pointed out, the use of new block (L537 and L553) and the shadowing of logger can be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 501 to 507
func (iter *CallIter) Next() bool {
if iter.End() {
return false
}
iter.cursor += 1
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • The return value of Next() is not used at all.
  • The last return statement should be fixed as follows, right?
    • return iter.End()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return value of Next means not that the cursor is end after Next call, but that the Next is procceeded or not(like return error).
But it is confusing and no one uses the returned value, I've simply drop return value.

Comment on lines 524 to 525
logAttrMsgIndexFrom, iter.Cursor(),
logAttrMsgIndexTo, iter.Cursor(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is msg_index_to inclusive or exclusive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The meaning of to is differ in logging context.
But it is not good.
Fix that all "to" means inclusive index.

logger = &log.RelayLogger{Logger: logger.With(
logAttrMsgIndexFrom, iter.Cursor(),
logAttrMsgIndexTo, iter.Cursor() + count,
logAttrMsgType, fmt.Sprintf("%T", iter.msgs[iter.Cursor() + count - 1]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this code only log the type of the last msg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modify to output all message types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and add log in case of multicall.Aggregate succeeded.

Comment on lines 615 to 618
count, err := findItems(
len(iter.msgs) - iter.Cursor(),
&data,
func(count int, d *Data) (error) {
Copy link
Contributor

@siburu siburu Jul 22, 2024

Choose a reason for hiding this comment

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

I think the second argument of findItems and the second argument of fnTest can be omitted, because fnTest is basically defined as a lambda and the lambda can directly access data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 675 to 717
func findItems[D any](
size int,
userdata *D,
fnTest func(int, *D) (error),
) (int, error) {
if (size <= 0) {
return 0, fmt.Errorf("empty items")
}

lastOkCount := 0
lastNgCount := 0

for true {
var count int

if lastNgCount == 0 {
count = size
if lastOkCount == count {
return lastOkCount, nil
}
} else if lastOkCount == 0 {
if lastNgCount == 1 {
return 0, fmt.Errorf("not found")
}
count = lastNgCount / 2 // note that lastNgCount >= 2
} else if lastOkCount + 1 == lastNgCount {
return lastOkCount, nil
} else {
count = (lastNgCount + lastOkCount) / 2
}

err := fnTest(count, userdata)
if err != nil {
if count == 1 {
return 0, err
}
lastNgCount = count
} else {
lastOkCount = count
}
}
return lastOkCount, nil // not reached
}
Copy link
Contributor

@siburu siburu Jul 22, 2024

Choose a reason for hiding this comment

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

Suggested change
func findItems[D any](
size int,
userdata *D,
fnTest func(int, *D) (error),
) (int, error) {
if (size <= 0) {
return 0, fmt.Errorf("empty items")
}
lastOkCount := 0
lastNgCount := 0
for true {
var count int
if lastNgCount == 0 {
count = size
if lastOkCount == count {
return lastOkCount, nil
}
} else if lastOkCount == 0 {
if lastNgCount == 1 {
return 0, fmt.Errorf("not found")
}
count = lastNgCount / 2 // note that lastNgCount >= 2
} else if lastOkCount + 1 == lastNgCount {
return lastOkCount, nil
} else {
count = (lastNgCount + lastOkCount) / 2
}
err := fnTest(count, userdata)
if err != nil {
if count == 1 {
return 0, err
}
lastNgCount = count
} else {
lastOkCount = count
}
}
return lastOkCount, nil // not reached
}
func findItems(size uint, f func(uint) error) (uint, error) {
if size <= 0 {
return 0, fmt.Errorf("empty items")
}
// hot path
if err := f(size); err == nil {
return size, nil
}
// binary search
if i := sort.Search(size-1, func(n int) bool { return f(n+1) != nil }); i == 0 {
return 0, fmt.Errorf("not found")
} else {
return i, nil
}
}

Copy link
Contributor Author

@dai1975 dai1975 Jul 23, 2024

Choose a reason for hiding this comment

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

I've not know sort.Search and replaced codes with yours.

pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Comment on lines 501 to 503
func (iter *CallIter) Current() *sdk.Msg {
return &iter.msgs[iter.cursor]
}
Copy link
Contributor

@siburu siburu Jul 23, 2024

Choose a reason for hiding this comment

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

@dai1975 sdk.Msg is not struct but interface.
We need not use a pointer to the interface here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
pkg/relay/ethereum/tx.go Outdated Show resolved Hide resolved
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Signed-off-by: Daisuke Kanda <dai1975@gmail.com>
Copy link
Contributor

@siburu siburu left a comment

Choose a reason for hiding this comment

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

@dai1975 LGTM. Thank you!!

@siburu siburu merged commit 28f687f into datachainlab:main Jul 24, 2024
1 check passed
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.

2 participants