-
Notifications
You must be signed in to change notification settings - Fork 222
Add pending tx and auto relay mechanism in RPC and CLI #1047
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
base: master-n3
Are you sure you want to change the base?
Changes from all commits
a03c0fb
4ccf6a6
6e8dd2a
5f31b0e
1efb8b5
2283f91
0ffa515
8cc3ef5
9a3a852
5a3ada3
bd81ea8
247bdce
05dca9a
acac851
356aee0
863c08c
0e4ac89
47d0ea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Neo.ConsoleService\Neo.ConsoleService.csproj" /> | ||
| <ProjectReference Include="..\RpcServer\RpcServer.csproj" AdditionalProperties="IncludeSettingsFileOutput=False"> | ||
| <Private>false</Private> | ||
| <ExcludeAssets>runtime</ExcludeAssets> | ||
| </ProjectReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="..\PluginHelper\PluginHelper.cs"> | ||
| <Link>PluginHelper\PluginHelper.cs</Link> | ||
| </Compile> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="DeferredRelay.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="$(PackageId).Tests" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "PluginConfiguration": { | ||
| "Path": "DeferredRelay_{0}", | ||
| "Network": 860833102, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can relay to a different network, so this value should be taken from the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No. It's no way to relay to another chain. If DeferredRelay.json Network ≠ the node’s ProtocolSettings.Network, OnSystemLoaded returns immediately: no store, no actor, no queue, no retry. The plugin does nothing on that node. Cross-chain relay is not possible here; The worst case is a silent misconfiguration (you think DeferredRelay is on, but it isn’t). |
||
| "MaxTransactions": 0, | ||
| "CheckFrequency": 0, | ||
| "UnhandledExceptionPolicy": "StopPlugin" | ||
| }, | ||
| "Dependency": [ | ||
| "RpcServer" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Copyright (C) 2015-2026 The Neo Project. | ||
| // | ||
| // DeferredRelayActor.cs file belongs to the neo project and is free | ||
| // software distributed under the MIT software license, see the | ||
| // accompanying file LICENSE in the main directory of the | ||
| // repository or http://www.opensource.org/licenses/mit-license.php | ||
| // for more details. | ||
| // | ||
| // Redistribution and use in source and binary forms with or without | ||
| // modifications are permitted. | ||
|
|
||
| using Akka.Actor; | ||
| using Neo.Ledger; | ||
| using Neo.Network.P2P.Payloads; | ||
| using Neo.Persistence; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Neo.Plugins.DeferredRelay; | ||
|
|
||
| internal sealed class DeferredRelayActor : UntypedActor | ||
| { | ||
| private sealed class ProcessQueuedCompleted; | ||
|
|
||
| private readonly NeoSystem _neo; | ||
| private readonly IStore _store; | ||
| private readonly DeferredRelaySettings _settings; | ||
| private bool _processingQueued; | ||
|
|
||
| public DeferredRelayActor(NeoSystem neo, IStore store, DeferredRelaySettings settings) | ||
| { | ||
| _neo = neo; | ||
| _store = store; | ||
| _settings = settings; | ||
| } | ||
|
|
||
| protected override void PreStart() | ||
| { | ||
| Context.System.EventStream.Subscribe(Self, typeof(Blockchain.RelayResult)); | ||
| Context.System.EventStream.Subscribe(Self, typeof(Blockchain.PersistCompleted)); | ||
| } | ||
|
|
||
| protected override void PostStop() => | ||
| Context.System.EventStream.Unsubscribe(Self); | ||
|
|
||
| protected override void OnReceive(object message) | ||
| { | ||
| switch (message) | ||
| { | ||
| case Blockchain.RelayResult { Inventory: Transaction tx, Result: VerifyResult.NotYetValid } rr: | ||
| DeferredRelayEngine.TryOffer(_neo, _store, _settings, tx, rr.Result); | ||
| break; | ||
| case Blockchain.PersistCompleted pc: | ||
| ScheduleProcessQueued(pc.Block); | ||
| break; | ||
| case ProcessQueuedCompleted: | ||
| _processingQueued = false; | ||
| break; | ||
| case Status.Failure failure: | ||
| _processingQueued = false; | ||
| Logs.RuntimeLogger.Warning(failure.Cause, "Deferred relay queue processing failed"); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| private void ScheduleProcessQueued(Block block) | ||
| { | ||
| if (_processingQueued || !DeferredRelayEngine.ShouldProcessPersist(block, _settings)) | ||
| return; | ||
|
|
||
| _processingQueued = true; | ||
| var self = Self; | ||
| _ = DeferredRelayEngine.ProcessQueuedAsync(_neo, _store) | ||
| .ContinueWith(t => | ||
| { | ||
| if (t.IsFaulted) | ||
| self.Tell(new Status.Failure(t.Exception!.GetBaseException())); | ||
| else | ||
| self.Tell(new ProcessQueuedCompleted()); | ||
| }, TaskScheduler.Default); | ||
| } | ||
| } |
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 the exclude?
Uh oh!
There was an error while loading. Please reload this page.
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.
RpcClient is not Plugin, it's SDK. I don't release it in zip package. It will be only update to Nuget.
MPTTire is packed inside StateService.zip, so it's not necessary to be packed alone again.