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

Avoid re-init properties #902

Closed
wants to merge 4 commits into from
Closed

Avoid re-init properties #902

wants to merge 4 commits into from

Conversation

shargon
Copy link
Member

@shargon shargon commented May 7, 2024

Copy link
Member

@cschuchardt88 cschuchardt88 left a comment

Choose a reason for hiding this comment

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

You need these or else you have to initialize each one, because they will be null or no instance when you do new(); ISerializable.Serialize or ISerializable.Deserialize will get exception object not set to an instance of an object. Also on some of them Size won't work because of that reason.

@shargon
Copy link
Member Author

shargon commented May 7, 2024

you have to initialize each one

Are always initialized, isn't it?

@cschuchardt88
Copy link
Member

cschuchardt88 commented May 7, 2024

No, you would have to do something like this:

var obj = new AClass()
{
  AProperty = new(),
}

@@ -33,16 +33,16 @@ public class TransactionLogState : ISerializable, IEquatable<TransactionLogState
public virtual void Deserialize(ref MemoryReader reader)
{
// It should be safe because it filled from a transaction's notifications.
uint aLen = reader.ReadUInt32();
var aLen = reader.ReadUInt32();
Copy link
Member

Choose a reason for hiding this comment

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

Is this related?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's just using dynamic type variable now; instead of being bound to a type specific variable.

@shargon
Copy link
Member Author

shargon commented May 7, 2024

No, you would have to do something like this:

var obj = new AClass()
{
  AProperty = new(),
}

It's currently done, otherwise you will have a default unused value, that will be changed in Create method

@cschuchardt88
Copy link
Member

cschuchardt88 commented May 7, 2024

Yes, But if someone was do bytes.AsSerializable<AClass>() it would throw that exception. This library was importable for other plugins to access the store.

Lets have @superboyiii test 1st. before merge.

@shargon
Copy link
Member Author

shargon commented May 8, 2024

Yes, But if someone was do bytes.AsSerializable<AClass>() it would throw that exception. This library was importable for other plugins to access the store.

Lets have @superboyiii test 1st. before merge.

Good point, but it call Deserialize

public Guid[] StackItemIds { get; protected set; } = [];
public UInt160 ScriptHash { get; protected set; }
public string EventName { get; protected set; }
public Guid[] StackItemIds { get; protected set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

@@ -15,9 +15,9 @@ namespace Neo.Plugins.Store.States
{
public class TransactionEngineLogState : ISerializable, IEquatable<TransactionEngineLogState>
{
public Guid[] LogIds { get; private set; } = Array.Empty<Guid>();
public Guid[] LogIds { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then set can't be private

Copy link
Member

@cschuchardt88 cschuchardt88 May 9, 2024

Choose a reason for hiding this comment

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

They have Create method and that should be used. Plus you still run into the same problem with null. So you need to add or remove changes on these files. I marked in review.

@@ -16,9 +16,9 @@ namespace ApplicationLogs.Store.States
{
public class TransactionLogState : ISerializable, IEquatable<TransactionLogState>
{
public Guid[] NotifyLogIds { get; private set; } = Array.Empty<Guid>();
public Guid[] NotifyLogIds { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

public VMState VmState { get; private set; }
public string Exception { get; private set; }
public long GasConsumed { get; private set; }
public Guid[] StackItemIds { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

public UInt160 ScriptHash { get; private set; } = new();
public string Message { get; private set; } = string.Empty;
public UInt160 ScriptHash { get; private set; }
public string Message { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

public UInt256 TransactionHash { get; private set; } = new();
public TriggerType Trigger { get; private set; } = TriggerType.All;
public UInt256 TransactionHash { get; private set; }
public TriggerType Trigger { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

@@ -16,9 +16,9 @@ namespace ApplicationLogs.Store.States
{
public class BlockLogState : ISerializable, IEquatable<BlockLogState>
{
public Guid[] NotifyLogIds { get; private set; } = [];
public Guid[] NotifyLogIds { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

We should make this required as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

like this? Kinda ugly:

public virtual void Deserialize(ref MemoryReader reader)
{
    // It should be safe because it filled from a block's notifications.
    var aLen = reader.ReadUInt32();
    var notifyLogIds = new Guid[aLen];
    for (var i = 0; i < aLen; i++)
        notifyLogIds[i] = new Guid(reader.ReadVarMemory().Span);

    // Create a new instance of BlockLogState using the Create factory method
    var blockLogState = Create(notifyLogIds);

    // Assign the created instance to the current object
    NotifyLogIds = blockLogState.NotifyLogIds;
}

@shargon
Copy link
Member Author

shargon commented May 21, 2024

Repository moved to neo, please re-open there

@shargon shargon closed this May 21, 2024
@shargon shargon deleted the core-optimizer-init branch May 21, 2024 08:04
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.

4 participants