Skip to content

Commit

Permalink
Rename: ValidatorPublicKey -> ValidatorPubKey (#7172)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit authored Jun 16, 2024
1 parent 1bb851d commit e1d3265
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WithdrawalRequest[] CalculateValidatorExits(IReleaseSpec spec, IWorldState state
WithdrawalRequest request = new();
Span<byte> span = new Span<byte>(result, i * sizeOfClass, sizeOfClass);
request.SourceAddress = new Address(span.Slice(0, 20).ToArray());
request.ValidatorPublicKey = span.Slice(20, 48).ToArray();
request.ValidatorPubkey = span.Slice(20, 48).ToArray();
request.Amount = BitConverter.ToUInt64(span.Slice(68, 8));

withdrawalRequests.Add(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IEnumerable<WithdrawalRequest> ReadWithdrawalRequests(IReleaseSpec spec,
WithdrawalRequest request = new();
Span<byte> span = new Span<byte>(result, i * sizeOfClass, sizeOfClass);
request.SourceAddress = new Address(span.Slice(0, 20).ToArray());
request.ValidatorPublicKey = span.Slice(20, 48).ToArray();
request.ValidatorPubkey = span.Slice(20, 48).ToArray();
request.Amount = BitConverter.ToUInt64(span.Slice(68, 8).ToArray().Reverse().ToArray()); // ToDo Optimize

yield return request;
Expand Down
12 changes: 6 additions & 6 deletions src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public static Hash256 KeccakFromNumber(int i)
public static Deposit DepositF_6Eth = new() { Index = 6, Pubkey = PublicKeyF.Bytes, Amount = 6_000_000_000, WithdrawalCredentials = AddressF.Bytes, Signature = KeccakF.Bytes.ToArray() };


public static WithdrawalRequest WithdrawalRequestA = new() { SourceAddress = AddressA, ValidatorPublicKey = PublicKeyA.Bytes };
public static WithdrawalRequest WithdrawalRequestB = new() { SourceAddress = AddressB, ValidatorPublicKey = PublicKeyB.Bytes };
public static WithdrawalRequest WithdrawalRequestC = new() { SourceAddress = AddressC, ValidatorPublicKey = PublicKeyC.Bytes };
public static WithdrawalRequest WithdrawalRequestD = new() { SourceAddress = AddressD, ValidatorPublicKey = PublicKeyD.Bytes };
public static WithdrawalRequest WithdrawalRequestE = new() { SourceAddress = AddressE, ValidatorPublicKey = PublicKeyE.Bytes };
public static WithdrawalRequest WithdrawalRequestF = new() { SourceAddress = AddressF, ValidatorPublicKey = PublicKeyF.Bytes };
public static WithdrawalRequest WithdrawalRequestA = new() { SourceAddress = AddressA, ValidatorPubkey = PublicKeyA.Bytes };
public static WithdrawalRequest WithdrawalRequestB = new() { SourceAddress = AddressB, ValidatorPubkey = PublicKeyB.Bytes };
public static WithdrawalRequest WithdrawalRequestC = new() { SourceAddress = AddressC, ValidatorPubkey = PublicKeyC.Bytes };
public static WithdrawalRequest WithdrawalRequestD = new() { SourceAddress = AddressD, ValidatorPubkey = PublicKeyD.Bytes };
public static WithdrawalRequest WithdrawalRequestE = new() { SourceAddress = AddressE, ValidatorPubkey = PublicKeyE.Bytes };
public static WithdrawalRequest WithdrawalRequestF = new() { SourceAddress = AddressF, ValidatorPubkey = PublicKeyF.Bytes };

public static IPEndPoint IPEndPointA = IPEndPoint.Parse("10.0.0.1");
public static IPEndPoint IPEndPointB = IPEndPoint.Parse("10.0.0.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public WithdrawalRequestBuilder WithSourceAddress(Address sourceAddress)
return this;
}

public WithdrawalRequestBuilder WithValidatorPubkey(byte[] validatorPubkey)
public WithdrawalRequestBuilder WithValidatorPubkey(byte[] ValidatorPubkey)
{
TestObject.ValidatorPublicKey = validatorPubkey;
TestObject.ValidatorPubkey = ValidatorPubkey;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public BlockDecoderTests()
}
else
{
byte[] validatorPubkey = new byte[48];
validatorPubkey[11] = 11;
byte[] ValidatorPubkey = new byte[48];
ValidatorPubkey[11] = 11;
requests[i] = Build.A.WithdrawalRequest
.WithSourceAddress(TestItem.AddressA)
.WithValidatorPubkey(validatorPubkey)
.WithValidatorPubkey(ValidatorPubkey)
.WithAmount(int.MaxValue)
.TestObject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public void Roundtrip_deposit()
[Test]
public void Roundtrip_withdrawalRequest()
{
byte[] validatorPubkey = new byte[48];
validatorPubkey[11] = 11;
byte[] ValidatorPubkey = new byte[48];
ValidatorPubkey[11] = 11;
ConsensusRequest withdrawalRequest = new WithdrawalRequest()
{
SourceAddress = TestItem.AddressA,
ValidatorPublicKey = validatorPubkey,
ValidatorPubkey = ValidatorPubkey,
Amount = int.MaxValue
};

Expand Down Expand Up @@ -78,7 +78,7 @@ public void Should_decode_withdrawalRequest_with_ValueDecoderContext()
ConsensusRequest withdrawalRequest = new WithdrawalRequest()
{
SourceAddress = TestItem.AddressA,
ValidatorPublicKey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
ValidatorPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
Amount = int.MaxValue
};
RlpStream stream = new(1024);
Expand Down Expand Up @@ -115,7 +115,7 @@ public void Should_encode_withdrawalRequest_same_for_Rlp_Encode_and_DepositDecod
ConsensusRequest withdrawalRequest = new WithdrawalRequest()
{
SourceAddress = TestItem.AddressA,
ValidatorPublicKey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
ValidatorPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
Amount = int.MaxValue
};
byte[] rlp1 = new ConsensusRequestDecoder().Encode(withdrawalRequest).Bytes;
Expand All @@ -140,7 +140,7 @@ public void Should_encode_ConsensusRequests_Array()
new WithdrawalRequest()
{
SourceAddress = TestItem.AddressA,
ValidatorPublicKey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
ValidatorPubkey = KeccakTests.KeccakOfAnEmptyString.ToBytes(),
Amount = int.MaxValue
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Address? SourceAddress
set { SourceAddressField = value; }
}

public byte[]? ValidatorPublicKey
public byte[]? ValidatorPubkey
{
get { return PubKeyField; }
set { PubKeyField = value; }
Expand All @@ -36,7 +36,7 @@ public ulong Amount

public string ToString(string indentation) => @$"{indentation}{nameof(WithdrawalRequest)}
{{{nameof(SourceAddress)}: {SourceAddress},
{nameof(ValidatorPublicKey)}: {ValidatorPublicKey?.ToHexString()},
{nameof(ValidatorPubkey)}: {ValidatorPubkey?.ToHexString()},
{nameof(Amount)}: {Amount}}}";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public int GetLength(WithdrawalRequest item, RlpBehaviors rlpBehaviors) =>
Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors));

public int GetContentLength(WithdrawalRequest item, RlpBehaviors rlpBehaviors) =>
Rlp.LengthOf(item.SourceAddress) + Rlp.LengthOf(item.ValidatorPublicKey) +
Rlp.LengthOf(item.SourceAddress) + Rlp.LengthOf(item.ValidatorPubkey) +
Rlp.LengthOf(item.Amount);

public WithdrawalRequest Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
int _ = rlpStream.ReadSequenceLength();
Address sourceAddress = rlpStream.DecodeAddress();
ArgumentNullException.ThrowIfNull(sourceAddress);
byte[] validatorPubkey = rlpStream.DecodeByteArray();
byte[] ValidatorPubkey = rlpStream.DecodeByteArray();
ulong amount = rlpStream.DecodeULong();
return new WithdrawalRequest()
{
SourceAddress = sourceAddress,
ValidatorPublicKey = validatorPubkey,
ValidatorPubkey = ValidatorPubkey,
Amount = amount
};
}
Expand All @@ -36,12 +36,12 @@ public WithdrawalRequest Decode(ref Rlp.ValueDecoderContext decoderContext, RlpB
int _ = decoderContext.ReadSequenceLength();
Address sourceAddress = decoderContext.DecodeAddress();
ArgumentNullException.ThrowIfNull(sourceAddress);
byte[] validatorPubkey = decoderContext.DecodeByteArray();
byte[] ValidatorPubkey = decoderContext.DecodeByteArray();
ulong amount = decoderContext.DecodeULong();
return new WithdrawalRequest()
{
SourceAddress = sourceAddress,
ValidatorPublicKey = validatorPubkey,
ValidatorPubkey = ValidatorPubkey,
Amount = amount
};
}
Expand All @@ -51,7 +51,7 @@ public void Encode(RlpStream stream, WithdrawalRequest item, RlpBehaviors rlpBeh
int contentLength = GetContentLength(item, rlpBehaviors);
stream.StartSequence(contentLength);
stream.Encode(item.SourceAddress);
stream.Encode(item.ValidatorPublicKey);
stream.Encode(item.ValidatorPubkey);
stream.Encode(item.Amount);
}

Expand Down

0 comments on commit e1d3265

Please sign in to comment.