Skip to content

Commit

Permalink
Move remaining changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergekh2 committed May 20, 2024
1 parent 548b388 commit f48f45a
Show file tree
Hide file tree
Showing 37 changed files with 231 additions and 163 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,7 @@ jobs:
working-directory: core

- name: Run node tests
# TODO: dropping --race for now, takes long and there is a flake in ./events that repores only on CI
run: go test -timeout 10m ./...
run: go test -race -timeout 12m ./...
working-directory: core/node

XChain_Node:
Expand Down
18 changes: 16 additions & 2 deletions contracts/scripts/deployments/DeployRiverBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {Deployer} from "../common/Deployer.s.sol";
import {River} from "contracts/src/tokens/river/base/River.sol";

contract DeployRiverBase is Deployer, IRiverBase {
address public bridgeBase = 0x4200000000000000000000000000000000000010;
address public l1Token = 0x40eF1bb984503bb5Adef041A88a4F9180e8586f9; // sepolia
address public bridgeBase = 0x4200000000000000000000000000000000000010; // L2StandardBridge
address public l1Token;

function versionName() public pure override returns (string memory) {
return "river";
Expand All @@ -22,7 +22,21 @@ contract DeployRiverBase is Deployer, IRiverBase {
uint256 deployerPK,
address
) public override returns (address) {
l1Token = _getToken();

vm.broadcast(deployerPK);
return address(new River({_bridge: bridgeBase, _remoteToken: l1Token}));
}

function _getToken() internal view returns (address) {
if (block.chainid == 8453) {
// if deploying to base use mainnet token
return 0x53319181e003E7f86fB79f794649a2aB680Db244;
} else if (block.chainid == 84532) {
// if deploying to base-sepolia use sepolia token
return 0x40eF1bb984503bb5Adef041A88a4F9180e8586f9;
} else {
return 0x40eF1bb984503bb5Adef041A88a4F9180e8586f9;
}
}
}
4 changes: 4 additions & 0 deletions contracts/src/tokens/lock/LockBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {ILockBase} from "./ILock.sol";
import {LockStorage} from "./LockStorage.sol";

abstract contract LockBase is ILockBase {
function __LockBase_init(uint256 cooldown) internal {
_setDefaultCooldown(cooldown);
}

modifier onlyAllowed() {
if (!_canLock()) revert LockNotAuthorized();
_;
Expand Down
6 changes: 1 addition & 5 deletions contracts/src/tokens/lock/LockFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ import {Facet} from "contracts/src/diamond/facets/Facet.sol";

abstract contract LockFacet is ILock, LockBase, Facet {
function __LockFacet_init(uint256 cooldown) external onlyInitializing {
__LockFacet_init_unchained(cooldown);
}

function __LockFacet_init_unchained(uint256 cooldown) internal {
__LockBase_init(cooldown);
_addInterface(type(ILock).interfaceId);
_setDefaultCooldown(cooldown);
}

/// @inheritdoc ILock
Expand Down
55 changes: 49 additions & 6 deletions contracts/src/tokens/river/base/River.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ILock} from "contracts/src/tokens/lock/ILock.sol";

// libraries
import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol";
Expand All @@ -19,18 +21,19 @@ import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20P
import {ERC20Votes} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

import {VotesEnumerable} from "contracts/src/diamond/facets/governance/votes/enumerable/VotesEnumerable.sol";
import {IntrospectionFacet} from "contracts/src/diamond/facets/introspection/IntrospectionFacet.sol";
import {LockFacet} from "contracts/src/tokens/lock/LockFacet.sol";
import {IntrospectionBase} from "contracts/src/diamond/facets/introspection/IntrospectionBase.sol";
import {LockBase} from "contracts/src/tokens/lock/LockBase.sol";

contract River is
IOptimismMintableERC20,
ILegacyMintableERC20,
ISemver,
ILock,
ERC20Permit,
ERC20Votes,
VotesEnumerable,
LockFacet,
IntrospectionFacet
IntrospectionBase,
LockBase
{
// =============================================================
// Errors
Expand Down Expand Up @@ -66,7 +69,7 @@ contract River is
address _remoteToken
) ERC20Permit("River") ERC20("River", "RVR") {
__IntrospectionBase_init();
__LockFacet_init_unchained(30 days);
__LockBase_init(30 days);

// add interface
_addInterface(type(IERC20).interfaceId);
Expand All @@ -76,6 +79,7 @@ contract River is
_addInterface(type(IOptimismMintableERC20).interfaceId);
_addInterface(type(ILegacyMintableERC20).interfaceId);
_addInterface(type(ISemver).interfaceId);
_addInterface(type(ILock).interfaceId);

// set the bridge
BRIDGE = _bridge;
Expand Down Expand Up @@ -131,7 +135,7 @@ contract River is
}

// =============================================================
// Overrides
// Votes
// =============================================================
/// @notice Clock used for flagging checkpoints, overriden to implement timestamp based
/// checkpoints (and voting).
Expand All @@ -150,6 +154,45 @@ contract River is
return super.nonces(owner);
}

// =============================================================
// Locking
// =============================================================

/// @inheritdoc ILock
function isLockEnabled(address account) external view virtual returns (bool) {
return _lockEnabled(account);
}

function lockCooldown(
address account
) external view virtual returns (uint256) {
return _lockCooldown(account);
}

/// @inheritdoc ILock
function enableLock(address account) external virtual onlyAllowed {
_enableLock(account);
}

/// @inheritdoc ILock
function disableLock(address account) external virtual onlyAllowed {
_disableLock(account);
}

/// @inheritdoc ILock
function setLockCooldown(uint256 cooldown) external virtual onlyAllowed {
_setDefaultCooldown(cooldown);
}

// =============================================================
// IERC165
// =============================================================

/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view returns (bool) {
return _supportsInterface(interfaceId);
}

// =============================================================
// Hooks
// =============================================================
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/tokens/river/mainnet/River.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ILock} from "contracts/src/tokens/lock/ILock.sol";

// libraries
import {Nonces} from "@openzeppelin/contracts/utils/Nonces.sol";
Expand Down Expand Up @@ -60,14 +61,15 @@ contract River is
RiverConfig memory config
) ERC20Permit("River") Ownable(config.owner) ERC20("River", "RVR") {
__IntrospectionBase_init();
__LockFacet_init_unchained(0 days);
__LockBase_init(0 days);

// add interface
_addInterface(type(IRiver).interfaceId);
_addInterface(type(IERC5805).interfaceId);
_addInterface(type(IERC20).interfaceId);
_addInterface(type(IERC20Metadata).interfaceId);
_addInterface(type(IERC20Permit).interfaceId);
_addInterface(type(ILock).interfaceId);

// mint to vault
_mint(config.vault, INITIAL_SUPPLY);
Expand Down
6 changes: 3 additions & 3 deletions core/node/crypto/chain_txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (r *transactionPool) Submit(
r.transactionGasCap.With(prometheus.Labels{"replacement": "false"}).Set(gasCap)
r.transactionGasTip.With(prometheus.Labels{"replacement": "false"}).Set(tipCap)

log.Info(
log.Debug(
"TxPool: Transaction SENT",
"txHash", tx.Hash(),
"chain", r.chainID,
Expand Down Expand Up @@ -436,7 +436,7 @@ func (r *transactionPool) OnBlock(ctx context.Context, blockNumber BlockNumber)
r.transactionsProcessed.With(prometheus.Labels{"status": status}).Inc()
r.transactionsPending.Add(-1)

log.Info(
log.Debug(
"TxPool: Transaction DONE",
"txHash", txHash,
"chain", r.chainID,
Expand Down Expand Up @@ -487,7 +487,7 @@ func (r *transactionPool) OnBlock(ctx context.Context, blockNumber BlockNumber)
}

if err := r.client.SendTransaction(ctx, tx); err == nil {
log.Info(
log.Debug(
"TxPool: Transaction REPLACED",
"old", pendingTx.tx.Hash(),
"txHash", tx.Hash(),
Expand Down
2 changes: 1 addition & 1 deletion core/node/events/stream_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewStreamCache(
) (*streamCacheImpl, error) {
s := &streamCacheImpl{
params: params,
registerMiniBlocksBatched: false,
registerMiniBlocksBatched: true,
}

streams, err := params.Registry.GetAllStreams(ctx, appliedBlockNum)
Expand Down
15 changes: 6 additions & 9 deletions core/node/events/stream_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,23 @@ func TestStreamCacheViewEviction(t *testing.T) {
testStreamCacheViewEviction(t, false)
})

// TODO: tests timeout on CI quite often, need to be stabilized.
// t.Run("BatchBlockRegistration", func(t *testing.T) {
// testStreamCacheViewEviction(t, true)
// })
t.Run("BatchBlockRegistration", func(t *testing.T) {
testStreamCacheViewEviction(t, true)
})
}

func TestCacheEvictionWithFilledMiniBlockPool(t *testing.T) {
t.Run("SingleBlockRegistration", func(t *testing.T) {
testCacheEvictionWithFilledMiniBlockPool(t, false)
})

// TODO: tests timeout on CI quite often, need to be stabilized.
// t.Run("BatchBlockRegistration", func(t *testing.T) {
// testCacheEvictionWithFilledMiniBlockPool(t, true)
// })
t.Run("BatchBlockRegistration", func(t *testing.T) {
testCacheEvictionWithFilledMiniBlockPool(t, true)
})
}

// TestStreamMiniblockBatchProduction ensures that all mini-blocks are registered when mini-blocks are registered in
// batches.
// TODO: tests timeout on CI quite often, need to be stabilized.
func DisabledTestStreamMiniblockBatchProduction(t *testing.T) {
t.Run("SingleBlockRegistration", func(t *testing.T) {
testStreamMiniblockBatchProduction(t, false)
Expand Down
3 changes: 2 additions & 1 deletion core/node/rules/can_add_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func (params *aeParams) canAddSpacePayload(payload *StreamEvent_SpacePayload) ru
}
if content.Channel.Op == ChannelOp_CO_UPDATED {
return aeBuilder().
check(params.creatorIsMember)
check(params.creatorIsMember).
check(ru.validSpaceChannelOp)
} else {
return aeBuilder().
check(params.creatorIsValidNode).
Expand Down
16 changes: 7 additions & 9 deletions core/proto/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ message SpacePayload {
}

message Channel {
reserved 5;
reserved 4, 5;
ChannelOp op = 1;
bytes channel_id = 2;
EventRef origin_event = 3;
EncryptedData channel_properties = 4;
}

oneof content {
Expand All @@ -241,14 +240,9 @@ message ChannelPayload {
}

message Inception {
reserved 6;
reserved 4, 6;
bytes stream_id = 1;
bytes space_id = 3;
/**
* channel_properties and is_default be used to
* create associated with that channel in the space stream
*/
EncryptedData channel_properties = 4;
StreamSettings settings = 5;
}

Expand Down Expand Up @@ -420,9 +414,13 @@ message UserSettingsPayload {
StreamSettings settings = 2;
}

message MarkerContent {
string data = 1;
}

message FullyReadMarkers {
bytes stream_id = 1;
EncryptedData content = 2;
MarkerContent content = 2;
}

message UserBlock {
Expand Down
3 changes: 0 additions & 3 deletions core/sdk/src/bob.test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ export const bobTalksToHimself = async (

const channelIdStr = makeUniqueChannelStreamId(spacedStreamIdStr)
const channelId = streamIdToBytes(channelIdStr)
const channelProperties = 'Bobs channel properties'

const channelInceptionEvent = await makeEvent(
bobsContext,
make_ChannelPayload_Inception({
streamId: channelId,
spaceId: spacedStreamId,
channelProperties: { ...TEST_ENCRYPTED_MESSAGE_PROPS, ciphertext: channelProperties },
}),
)
const channelJoinEvent = await makeEvent(
Expand Down Expand Up @@ -127,7 +125,6 @@ export const bobTalksToHimself = async (
)
expect(channelCreatePayload).toBeDefined()
expect(channelCreatePayload?.channelId).toEqual(channelId)
expect(channelCreatePayload?.channelProperties?.ciphertext).toEqual(channelProperties)

await maybeFlush()

Expand Down
14 changes: 4 additions & 10 deletions core/sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import {
StreamTimelineEvent,
make_UserInboxPayload_Ack,
make_UserInboxPayload_Inception,
make_fake_encryptedData,
make_UserDeviceKeyPayload_EncryptionDevice,
make_UserInboxPayload_GroupEncryptionSessions,
ParsedStreamResponse,
Expand Down Expand Up @@ -530,9 +529,6 @@ export class Client
make_ChannelPayload_Inception({
streamId: channelId,
spaceId: streamIdAsBytes(spaceId),
channelProperties: make_fake_encryptedData(
make_ChannelProperties(channelName, channelTopic).toJsonString(),
),
settings: streamSettings,
}),
)
Expand Down Expand Up @@ -691,20 +687,18 @@ export class Client
async updateChannel(
spaceId: string | Uint8Array,
channelId: string | Uint8Array,
channelName: string,
channelTopic: string,
unused1: string,
unused2: string,
) {
this.logCall('updateChannel', channelId, spaceId, channelName, channelTopic)
this.logCall('updateChannel', channelId, spaceId, unused1, unused2)
assert(isSpaceStreamId(spaceId), 'spaceId must be a valid streamId')
assert(isChannelStreamId(channelId), 'channelId must be a valid streamId')
const channelProps = make_ChannelProperties(channelName, channelTopic).toJsonString()

return this.makeEventAndAddToStream(
spaceId, // we send events to the stream of the space where updated channel belongs to
make_SpacePayload_Channel({
op: ChannelOp.CO_UPDATED,
channelId: streamIdAsBytes(channelId),
channelProperties: make_fake_encryptedData(channelProps),
}),
{ method: 'updateChannel' },
)
Expand Down Expand Up @@ -742,7 +736,7 @@ export class Client
this.userSettingsStreamId,
make_UserSettingsPayload_FullyReadMarkers({
streamId: streamIdAsBytes(channelId),
content: make_fake_encryptedData(fullyReadMarkersContent.toJsonString()),
content: { data: fullyReadMarkersContent.toJsonString() },
}),
{ method: 'sendFullyReadMarker' },
)
Expand Down
Loading

0 comments on commit f48f45a

Please sign in to comment.