Skip to content

Commit

Permalink
Move from using UnsignedLong to Uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Feb 15, 2019
1 parent 9834449 commit eb4ef00
Show file tree
Hide file tree
Showing 47 changed files with 792 additions and 839 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

package tech.pegasys.artemis.datastructures;

import com.google.common.primitives.UnsignedLong;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.bytes.Bytes32;
import net.consensys.cava.bytes.Bytes48;
import net.consensys.cava.units.bigints.UInt64;
import tech.pegasys.artemis.datastructures.operations.BLSSignature;

public final class Constants {
Expand All @@ -27,7 +27,7 @@ public final class Constants {
public static final int TARGET_COMMITTEE_SIZE = 128; // 2^7 validators
public static final long EJECTION_BALANCE = 16000000000L; // 2^4 * 1e9 Gwei
public static final int MAX_BALANCE_CHURN_QUOTIENT = 32; //
public static final UnsignedLong BEACON_CHAIN_SHARD_NUMBER = UnsignedLong.MAX_VALUE; // 2^64 - 1
public static final UInt64 BEACON_CHAIN_SHARD_NUMBER = UInt64.MAX_VALUE; // 2^64 - 1
public static final int MAX_INDICES_PER_SLASHABLE_VOTE = 4096; // 2^12 votes
public static final int MAX_WITHDRAWALS_PER_EPOCH = 4; // withdrawals

Expand All @@ -42,7 +42,7 @@ public final class Constants {
public static final long GENESIS_SLOT = 524288l; // 2^19
public static final long GENESIS_EPOCH = slot_to_epoch(GENESIS_SLOT);
public static final long GENESIS_START_SHARD = 0;
public static UnsignedLong FAR_FUTURE_EPOCH = UnsignedLong.MAX_VALUE; //
public static UInt64 FAR_FUTURE_EPOCH = UInt64.MAX_VALUE; //
public static Bytes32 ZERO_HASH = Bytes32.ZERO; //
public static final BLSSignature EMPTY_SIGNATURE =
new BLSSignature(Bytes48.ZERO, Bytes48.ZERO); // Bytes96
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

package tech.pegasys.artemis.datastructures.blocks;

import com.google.common.primitives.UnsignedLong;
import java.util.Objects;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.ssz.SSZ;
import net.consensys.cava.units.bigints.UInt64;

public final class Eth1DataVote {

private Eth1Data eth1_data;
private UnsignedLong vote_count;
private UInt64 vote_count;

public Eth1DataVote(Eth1Data eth1_data, UnsignedLong vote_count) {
public Eth1DataVote(Eth1Data eth1_data, UInt64 vote_count) {
this.eth1_data = eth1_data;
this.vote_count = vote_count;
}
Expand All @@ -33,15 +33,14 @@ public static Eth1DataVote fromBytes(Bytes bytes) {
bytes,
reader ->
new Eth1DataVote(
Eth1Data.fromBytes(reader.readBytes()),
UnsignedLong.fromLongBits(reader.readUInt64())));
Eth1Data.fromBytes(reader.readBytes()), UInt64.valueOf(reader.readUInt64())));
}

public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeBytes(eth1_data.toBytes());
writer.writeUInt64(vote_count.longValue());
writer.writeUInt64(vote_count.toLong());
});
}

Expand Down Expand Up @@ -80,12 +79,12 @@ public void setEth1_data(Eth1Data eth1_data) {
}

/** @return the vote_count */
public UnsignedLong getVote_count() {
public UInt64 getVote_count() {
return vote_count;
}

/** @param vote_count the vote_count to set */
public void setVote_count(UnsignedLong vote_count) {
public void setVote_count(UInt64 vote_count) {
this.vote_count = vote_count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

package tech.pegasys.artemis.datastructures.blocks;

import com.google.common.primitives.UnsignedLong;
import java.util.Objects;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.bytes.Bytes32;
import net.consensys.cava.ssz.SSZ;
import net.consensys.cava.units.bigints.UInt64;

public class ProposalSignedData {

private UnsignedLong slot;
private UnsignedLong shard;
private UInt64 slot;
private UInt64 shard;
private Bytes32 block_root;

public ProposalSignedData(UnsignedLong slot, UnsignedLong shard, Bytes32 block_root) {
public ProposalSignedData(UInt64 slot, UInt64 shard, Bytes32 block_root) {
this.slot = slot;
this.shard = shard;
this.block_root = block_root;
Expand All @@ -36,16 +36,16 @@ public static ProposalSignedData fromBytes(Bytes bytes) {
bytes,
reader ->
new ProposalSignedData(
UnsignedLong.fromLongBits(reader.readUInt64()),
UnsignedLong.fromLongBits(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
Bytes32.wrap(reader.readBytes())));
}

public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeUInt64(slot.longValue());
writer.writeUInt64(shard.longValue());
writer.writeUInt64(slot.toLong());
writer.writeUInt64(shard.toLong());
writer.writeBytes(block_root);
});
}
Expand Down Expand Up @@ -76,19 +76,19 @@ public boolean equals(Object obj) {
}

/** ******************* * GETTERS & SETTERS * * ******************* */
public UnsignedLong getSlot() {
public UInt64 getSlot() {
return slot;
}

public void setSlot(UnsignedLong slot) {
public void setSlot(UInt64 slot) {
this.slot = slot;
}

public UnsignedLong getShard() {
public UInt64 getShard() {
return shard;
}

public void setShard(UnsignedLong shard) {
public void setShard(UInt64 shard) {
this.shard = shard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@

package tech.pegasys.artemis.datastructures.operations;

import com.google.common.primitives.UnsignedLong;
import java.util.Objects;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.bytes.Bytes32;
import net.consensys.cava.ssz.SSZ;
import net.consensys.cava.units.bigints.UInt64;

public class AttestationData {

private UnsignedLong slot;
private UnsignedLong shard;
private UInt64 slot;
private UInt64 shard;
private Bytes32 beacon_block_root;
private Bytes32 epoch_boundary_root;
private Bytes32 shard_block_root;
private Bytes32 latest_crosslink_root;
private UnsignedLong justified_epoch;
private UInt64 justified_epoch;
private Bytes32 justified_block_root;

public AttestationData(
UnsignedLong slot,
UnsignedLong shard,
UInt64 slot,
UInt64 shard,
Bytes32 beacon_block_root,
Bytes32 epoch_boundary_root,
Bytes32 shard_block_root,
Bytes32 latest_crosslink_root,
UnsignedLong justified_epoch,
UInt64 justified_epoch,
Bytes32 justified_block_root) {
this.slot = slot;
this.shard = shard;
Expand All @@ -54,26 +54,26 @@ public static AttestationData fromBytes(Bytes bytes) {
bytes,
reader ->
new AttestationData(
UnsignedLong.fromLongBits(reader.readUInt64()),
UnsignedLong.fromLongBits(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
Bytes32.wrap(reader.readBytes()),
Bytes32.wrap(reader.readBytes()),
Bytes32.wrap(reader.readBytes()),
Bytes32.wrap(reader.readBytes()),
UnsignedLong.fromLongBits(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
Bytes32.wrap(reader.readBytes())));
}

public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeUInt64(slot.longValue());
writer.writeUInt64(shard.longValue());
writer.writeUInt64(slot.toLong());
writer.writeUInt64(shard.toLong());
writer.writeBytes(beacon_block_root);
writer.writeBytes(epoch_boundary_root);
writer.writeBytes(shard_block_root);
writer.writeBytes(latest_crosslink_root);
writer.writeUInt64(justified_epoch.longValue());
writer.writeUInt64(justified_epoch.toLong());
writer.writeBytes(justified_block_root);
});
}
Expand Down Expand Up @@ -117,11 +117,11 @@ public boolean equals(Object obj) {
}

/** ******************* * GETTERS & SETTERS * * ******************* */
public UnsignedLong getSlot() {
public UInt64 getSlot() {
return slot;
}

public void setSlot(UnsignedLong slot) {
public void setSlot(UInt64 slot) {
this.slot = slot;
}

Expand Down Expand Up @@ -149,11 +149,11 @@ public void setShard_block_root(Bytes32 shard_block_root) {
this.shard_block_root = shard_block_root;
}

public UnsignedLong getShard() {
public UInt64 getShard() {
return shard;
}

public void setShard(UnsignedLong shard) {
public void setShard(UInt64 shard) {
this.shard = shard;
}

Expand All @@ -165,11 +165,11 @@ public void setLatest_crosslink_root(Bytes32 latest_crosslink_root) {
this.latest_crosslink_root = latest_crosslink_root;
}

public UnsignedLong getJustified_epoch() {
public UInt64 getJustified_epoch() {
return justified_epoch;
}

public void setJustified_epoch(UnsignedLong justified_epoch) {
public void setJustified_epoch(UInt64 justified_epoch) {
this.justified_epoch = justified_epoch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@

package tech.pegasys.artemis.datastructures.operations;

import com.google.common.primitives.UnsignedLong;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.bytes.Bytes32;
import net.consensys.cava.ssz.SSZ;
import net.consensys.cava.units.bigints.UInt64;

public class Deposit {

private List<Bytes32> branch;
private UnsignedLong index;
private UInt64 index;
private DepositData deposit_data;

public Deposit(List<Bytes32> branch, UnsignedLong index, DepositData deposit_data) {
public Deposit(List<Bytes32> branch, UInt64 index, DepositData deposit_data) {
this.branch = branch;
this.index = index;
this.deposit_data = deposit_data;
Expand All @@ -39,15 +39,15 @@ public static Deposit fromBytes(Bytes bytes) {
reader ->
new Deposit(
reader.readBytesList().stream().map(Bytes32::wrap).collect(Collectors.toList()),
UnsignedLong.fromLongBits(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
DepositData.fromBytes(reader.readBytes())));
}

public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeBytesList(branch);
writer.writeUInt64(index.longValue());
writer.writeUInt64(index.toLong());
writer.writeBytes(deposit_data.toBytes());
});
}
Expand Down Expand Up @@ -86,11 +86,11 @@ public void setBranch(List<Bytes32> branch) {
this.branch = branch;
}

public UnsignedLong getIndex() {
public UInt64 getIndex() {
return index;
}

public void setIndex(UnsignedLong index) {
public void setIndex(UInt64 index) {
this.index = index;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

package tech.pegasys.artemis.datastructures.operations;

import com.google.common.primitives.UnsignedLong;
import java.util.Objects;
import net.consensys.cava.bytes.Bytes;
import net.consensys.cava.ssz.SSZ;
import net.consensys.cava.units.bigints.UInt64;

public class DepositData {

private UnsignedLong amount;
private UnsignedLong timestamp;
private UInt64 amount;
private UInt64 timestamp;
private DepositInput deposit_input;

public DepositData(UnsignedLong amount, UnsignedLong timestamp, DepositInput deposit_input) {
public DepositData(UInt64 amount, UInt64 timestamp, DepositInput deposit_input) {
this.amount = amount;
this.timestamp = timestamp;
this.deposit_input = deposit_input;
Expand All @@ -35,16 +35,16 @@ public static DepositData fromBytes(Bytes bytes) {
bytes,
reader ->
new DepositData(
UnsignedLong.fromLongBits(reader.readUInt64()),
UnsignedLong.fromLongBits(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
UInt64.valueOf(reader.readUInt64()),
DepositInput.fromBytes(reader.readBytes())));
}

public Bytes toBytes() {
return SSZ.encode(
writer -> {
writer.writeUInt64(amount.longValue());
writer.writeUInt64(timestamp.longValue());
writer.writeUInt64(amount.toLong());
writer.writeUInt64(timestamp.toLong());
writer.writeBytes(deposit_input.toBytes());
});
}
Expand Down Expand Up @@ -83,19 +83,19 @@ public void setDeposit_input(DepositInput deposit_input) {
this.deposit_input = deposit_input;
}

public UnsignedLong getAmount() {
public UInt64 getAmount() {
return amount;
}

public void setAmount(UnsignedLong amount) {
public void setAmount(UInt64 amount) {
this.amount = amount;
}

public UnsignedLong getTimestamp() {
public UInt64 getTimestamp() {
return timestamp;
}

public void setTimestamp(UnsignedLong timestamp) {
public void setTimestamp(UInt64 timestamp) {
this.timestamp = timestamp;
}
}
Loading

0 comments on commit eb4ef00

Please sign in to comment.