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

fix: start from initialBlockNumber, build settings, fix github actions, and other minor additions #137

Merged
merged 7 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/mud-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:
- name: git-checkout
uses: actions/checkout@v2

- name: Clean yarn cache
run: yarn cache clean

- name: Install dependencies
run: yarn
run: yarn install --network-concurrency 1

- name: Build docs
run: yarn docs # Build fresh docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v2

- name: Install dependencies
run: yarn
run: yarn install --network-concurrency 1

- name: Run tests
run: yarn test
1 change: 1 addition & 0 deletions packages/ecs-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"mobx-react-lite": "^3.4.0",
"react": "^18.1.0",
"react-collapse": "^5.1.1",
"react-dom": "^18.2.0",
"react-syntax-highlighter": "^15.5.0",
"rimraf": "^3.0.2",
"rollup": "^2.69.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ecs-browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2019" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand Down
22 changes: 15 additions & 7 deletions packages/network/src/workers/SyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class SyncWorker<Cm extends Components> implements DoWork<SyncWorkerConfi
chainId,
worldContract,
provider: { options: providerOptions },
initialBlockNumber,
} = computedConfig.get();

// Set up
Expand Down Expand Up @@ -84,17 +85,24 @@ export class SyncWorker<Cm extends Components> implements DoWork<SyncWorkerConfi
// Load initial state from cache or snapshot service
const cacheBlockNumber = await getIndexDBCacheStoreBlockNumber(indexDbCache);
const snapshotBlockNumber = await getSnapshotBlockNumber(snapshotClient, worldContract.address);
const syncFromSnapshot = snapshotClient && snapshotBlockNumber > cacheBlockNumber + 100; // Load from cache if the snapshot is less than 100 blocks newer than the cache
console.log(`[SyncWorker] cache block: ${cacheBlockNumber}, snapshot block: ${snapshotBlockNumber}`);
const initialState = syncFromSnapshot
? await fetchSnapshot(snapshotClient, worldContract.address, decode)
: await loadIndexDbCacheStore(indexDbCache);
console.log(`[SyncWorker] got ${initialState.state.size} items from ${syncFromSnapshot ? "snapshot" : "cache"}`);
console.log(
`[SyncWorker] cache block: ${cacheBlockNumber}, snapshot block: ${snapshotBlockNumber}, start sync at ${initialBlockNumber}`
);
let initialState = createCacheStore();
if (initialBlockNumber > Math.max(cacheBlockNumber, snapshotBlockNumber)) {
initialState.blockNumber = initialBlockNumber;
} else {
const syncFromSnapshot = snapshotClient && snapshotBlockNumber > cacheBlockNumber + 100; // Load from cache if the snapshot is less than 100 blocks newer than the cache
initialState = syncFromSnapshot
? await fetchSnapshot(snapshotClient, worldContract.address, decode)
: await loadIndexDbCacheStore(indexDbCache);
console.log(`[SyncWorker] got ${initialState.state.size} items from ${syncFromSnapshot ? "snapshot" : "cache"}`);
}

// Load events from gap between initial state and current block number from RPC
const gapState = await fetchStateInBlockRange(
fetchWorldEvents,
initialState.blockNumber,
initialState.blockNumber || initialBlockNumber,
await streamStartBlockNumber
);
console.log(
Expand Down
3 changes: 2 additions & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"prepare": "make build",
"docs": "typedoc . --readme README.md",
"test": "echo 'todo: add tests'"
"test": "echo 'todo: add tests'",
"link": "yarn link"
},
"devDependencies": {
"@protobuf-ts/grpcweb-transport": "^2.7.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/solecs/src/System.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ abstract contract System is ISystem {
IWorld world;
address _owner;

modifier onlyOwner() {
require(msg.sender == _owner, "ONLY_OWNER");
_;
}

constructor(IWorld _world, address _components) {
_owner = msg.sender;
components = _components == address(0) ? _world.components() : IUint256Component(_components);
Expand Down
27 changes: 27 additions & 0 deletions packages/std-contracts/src/components/StringArrayComponent.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;
import "solecs/Component.sol";

contract StringArrayComponent is Component {
constructor(address world, uint256 id) Component(world, id) {}

function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) {
keys = new string[](1);
values = new LibTypes.SchemaValue[](1);

keys[0] = "value";
values[0] = LibTypes.SchemaValue.STRING_ARRAY;
}

function set(uint256 entity, string[] memory value) public {
set(entity, abi.encode(value));
}

function getValue(uint256 entity) public view returns (string[] memory) {
return abi.decode(getRawValue(entity), (string[]));
}

function getEntitiesWithValue(string[] memory value) public view returns (uint256[] memory) {
return getEntitiesWithValue(abi.encode(value));
}
}