-
Notifications
You must be signed in to change notification settings - Fork 14
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
multicall #48
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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.
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
rebase. |
There was a problem hiding this 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
{ | ||
logger := &log.RelayLogger{Logger: logger.Logger} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
func (iter *CallIter) Next() bool { | ||
if iter.End() { | ||
return false | ||
} | ||
iter.cursor += 1 | ||
return true | ||
} |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
pkg/relay/ethereum/tx.go
Outdated
logAttrMsgIndexFrom, iter.Cursor(), | ||
logAttrMsgIndexTo, iter.Cursor(), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
pkg/relay/ethereum/tx.go
Outdated
logger = &log.RelayLogger{Logger: logger.With( | ||
logAttrMsgIndexFrom, iter.Cursor(), | ||
logAttrMsgIndexTo, iter.Cursor() + count, | ||
logAttrMsgType, fmt.Sprintf("%T", iter.msgs[iter.Cursor() + count - 1]), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/relay/ethereum/tx.go
Outdated
count, err := findItems( | ||
len(iter.msgs) - iter.Cursor(), | ||
&data, | ||
func(count int, d *Data) (error) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
} | |
} |
There was a problem hiding this comment.
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.
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
pkg/relay/ethereum/tx.go
Outdated
func (iter *CallIter) Current() *sdk.Msg { | ||
return &iter.msgs[iter.cursor] | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Signed-off-by: Daisuke Kanda <[email protected]>
Signed-off-by: Daisuke Kanda <[email protected]>
There was a problem hiding this 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!!
Send tx by using Multicall3