-
Notifications
You must be signed in to change notification settings - Fork 473
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
Feature/recover whole path #8120
base: master
Are you sure you want to change the base?
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.
Love the idea!
/// Automatically cancel and dispose underlying cancellation token source. | ||
/// Make it easy to have golang style defer cancel pattern. | ||
/// </summary> | ||
public readonly struct AutoCancelTokenSource(CancellationTokenSource cancellationTokenSource) : IDisposable |
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 not derive from CancellationTokenSource?
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 prefer not to use inheritance.
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 somewhat agree, but it IS a CancellationTokenSource, so it makes some sense
/// <param name="tasks"></param> | ||
/// <typeparam name="T"></typeparam> | ||
/// <returns></returns> | ||
public static async Task<T> ForPassingTask<T>(Func<T, bool> cond, params IEnumerable<Task<T>> tasks) |
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.
Can we make it span?
LINQ style naming? AnyWhere
or just Any
- in LINQ it has optional parameter:https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any?view=net-8.0#system-linq-enumerable-any-1(system-collections-generic-ienumerable((-0))-system-func((-0-system-boolean)))
public static async Task<T> ForPassingTask<T>(Func<T, bool> cond, params IEnumerable<Task<T>> tasks) | |
public static async Task<T> AnyWhere<T>(Func<T, bool> predicate, params ReadOnlySpan<Task<T>> tasks) |
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.
Because its an async code.
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.
Ok the naming comment still stands
if (!taskSet.Any()) | ||
{ | ||
// No more tasks, just return the last one. | ||
return result; |
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.
shouldn't we return null or just TaskCompleated with default value?
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.
Hmmm... don't know.
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.
Well, it does make nullability simple.
@@ -204,7 +204,7 @@ private void UpdateValue(ref decimal? currentValue, decimal newValue) | |||
{ | |||
return (long?)(transferSpeedType switch | |||
{ | |||
TransferSpeedType.Latency => _averageLatency, | |||
TransferSpeedType.Latency => _averageLatency ?? 10000, |
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.
const from some timeout? int.MaxValue?
cancellationToken); | ||
} | ||
|
||
public static async Task<T> AllocateAndRun2<T>( |
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.
confused about the naming, can we just name it AllocateAndRun
?
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.
AllocateAndRun
already used.
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.
but has different parameters?
nodeRlp = await FetchRlp(rootHash, address, currentPath, currentHash, cts.Token); | ||
} | ||
|
||
if (nodeRlp == null) |
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 null
queryPath = newQueryPath; | ||
} | ||
|
||
Dictionary<TreePath, byte[]> recoveredNodes = new(); |
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.
Does it make sense to be Dictionary
? Wouldn't list suffice? (could use pooledList)
return null; | ||
}, NodePeerStrategy, AllocationContexts.State, cancellationToken); | ||
}) | ||
.ToArray(); |
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.
ToPooledList
instead of array
return null; | ||
}, SnapPeerStrategy, AllocationContexts.Snap, cts.Token); | ||
}) | ||
.ToArray(); |
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.
ToPooledList
// Sometimes the start path for the missing node and the actual full path that the trie is working on is not the same. | ||
// So we change the query to match the missing node path. | ||
if (new TreePath(queryPath, 64).Truncate(startingPath.Length) != startingPath) | ||
{ | ||
int remainingLength = 64 - startingPath.Length; | ||
TreePath newQueryPath = startingPath; | ||
for (int i = 0; i < remainingLength; i++) | ||
{ | ||
newQueryPath.Append(0); | ||
} | ||
queryPath = newQueryPath.Path; | ||
} |
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.
Same code as the other one?
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing