Skip to content

Commit

Permalink
Merge branch 'master' into gabor/nixpkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk authored Feb 19, 2023
2 parents 0f13c4d + 80875f3 commit 549cf38
Show file tree
Hide file tree
Showing 25 changed files with 1,133 additions and 680 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ jobs:
if [[ -d "${{ steps.buildit.outputs.out }}/build/libs" ]]
then
tar -C "${{ steps.buildit.outputs.out }}/build" -czvf ic-ref.tar.gz ic-ref libs
tar -C "${{ steps.buildit.outputs.out }}" -czvf ic-ref-test.tar.gz build/ic-ref-test build/libs test-data
else
tar -C "${{ steps.buildit.outputs.out }}/build" -czvf ic-ref.tar.gz ic-ref
tar -C "${{ steps.buildit.outputs.out }}" -czvf ic-ref-test.tar.gz build/ic-ref-test test-data
fi
tar -C "${{ steps.buildit.outputs.out }}" -czvf ic-ref-test.tar.gz build test-data
ref_short="$(echo "$GITHUB_SHA" | cut -c1-8)"
version="${{ steps.get_version.outputs.version }}-$ref_short"
Expand Down
1 change: 0 additions & 1 deletion cabal.project.freeze

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ rec {
test -e port
mkdir -p $out
sleep 1
LANG=C.UTF8 ic-ref-test --ecid 5v3p4-iyaaa-aaaaa-qaaaa-cai --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003" --html $out/report.html
LANG=C.UTF8 ic-ref-test --test-subnet-config "(\"bn26o-3iapb-njhsq-6mjum-ssjtx-lcwrs-id2x6-2z7ce-yaweh-xamz5-7qe\",system,1,[(0,1048575)])" --peer-subnet-config "(\"jdzfx-2szde-tnkmk-2m5zt-t6gga-pnl22-v36hx-hz5zg-r6mei-tw3q4-nae\",application,1,[(1048576,2097151)])" --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003" --html $out/report-1.html
LANG=C.UTF8 ic-ref-test --test-subnet-config "(\"jdzfx-2szde-tnkmk-2m5zt-t6gga-pnl22-v36hx-hz5zg-r6mei-tw3q4-nae\",application,1,[(1048576,2097151)])" --peer-subnet-config "(\"bn26o-3iapb-njhsq-6mjum-ssjtx-lcwrs-id2x6-2z7ce-yaweh-xamz5-7qe\",system,1,[(0,1048575)])" --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003" --html $out/report-2.html
pids="$(jobs -p)"
kill -INT $pids
trap - EXIT PIPE
mkdir -p $out/nix-support
echo "report test-results $out report.html" >> $out/nix-support/hydra-build-products
echo "report test-results $out report-1.html" >> $out/nix-support/hydra-build-products
echo "report test-results $out report-2.html" >> $out/nix-support/hydra-build-products
'';

coverage = nixpkgs.runCommandNoCC "ic-ref-test" {
Expand All @@ -217,7 +219,8 @@ rec {
sleep 1
test -e port
sleep 1
LANG=C.UTF8 ic-ref-test --ecid 5v3p4-iyaaa-aaaaa-qaaaa-cai --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003"
LANG=C.UTF8 ic-ref-test --test-subnet-config "(\"bn26o-3iapb-njhsq-6mjum-ssjtx-lcwrs-id2x6-2z7ce-yaweh-xamz5-7qe\",system,1,[(0,1048575)])" --peer-subnet-config "(\"jdzfx-2szde-tnkmk-2m5zt-t6gga-pnl22-v36hx-hz5zg-r6mei-tw3q4-nae\",application,1,[(1048576,2097151)])" --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003"
LANG=C.UTF8 ic-ref-test --test-subnet-config "(\"jdzfx-2szde-tnkmk-2m5zt-t6gga-pnl22-v36hx-hz5zg-r6mei-tw3q4-nae\",application,1,[(1048576,2097151)])" --peer-subnet-config "(\"bn26o-3iapb-njhsq-6mjum-ssjtx-lcwrs-id2x6-2z7ce-yaweh-xamz5-7qe\",system,1,[(0,1048575)])" --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003"
pids="$(jobs -p)"
kill -INT $pids
trap - EXIT PIPE
Expand Down
3 changes: 0 additions & 3 deletions ic-hs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ executable ic-ref-test
build-depends: asn1-types
build-depends: base32
build-depends: base >=4.12 && <5
build-depends: base64 >= 0.4.2.4
build-depends: base64-bytestring >= 1.1
build-depends: binary
build-depends: bytestring
Expand Down Expand Up @@ -446,7 +445,6 @@ test-suite unit-test
build-depends: base32
build-depends: base >=4.12 && <5
build-depends: base >= 4 && < 5
build-depends: base64 >= 0.4.2.4
build-depends: base64-bytestring >= 1.1
build-depends: binary
build-depends: bytestring
Expand Down Expand Up @@ -565,7 +563,6 @@ library
build-depends: base32
build-depends: base >=4.12 && <5
build-depends: base >= 4 && < 5
build-depends: base64 >= 0.4.2.4
build-depends: base64-bytestring >= 1.1
build-depends: binary
build-depends: bytestring
Expand Down
5 changes: 3 additions & 2 deletions ic.did
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ service ic : {
http_request : (record {
url : text;
max_response_bytes: opt nat64;
method : variant { get; post; head };
method : variant { get; head; post };
headers: vec http_header;
body : opt blob;
transform : opt record {
Expand All @@ -81,7 +81,8 @@ service ic : {
// provisional interfaces for the pre-ledger world
provisional_create_canister_with_cycles : (record {
amount: opt nat;
settings : opt canister_settings
settings : opt canister_settings;
specified_id: opt canister_id;
}) -> (record {canister_id : canister_id});
provisional_top_up_canister :
(record { canister_id: canister_id; amount: nat }) -> ();
Expand Down
4 changes: 0 additions & 4 deletions nix/generated/ic-hs.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions src/IC/Canister/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import IC.Types
import IC.Wasm.Winter
import IC.Wasm.Imports
import IC.Canister.StableMemory as Mem
import IC.Id.Fresh
import IC.Utils

{-
Expand Down Expand Up @@ -114,7 +115,7 @@ ic0.data_certificate_size : () -> i32; // *
ic0.data_certificate_copy : (dst: i32, offset: i32, size: i32) -> (); // *
ic0.time : () -> (timestamp : i64); // *
ic0.global_timer_set : (timestamp : i64) -> i64; // I U Ry Rt C T
ic0.global_timer_set : (timestamp : i64) -> i64; // I G U Ry Rt C T
ic0.performance_counter : (counter_type : i32) -> (counter : i64); // * s
ic0.debug_print : (src : i32, size : i32) -> (); // * s
Expand Down Expand Up @@ -176,6 +177,7 @@ data ExecutionState s = ExecutionState
-- now the mutable parts
, cycles_available :: Maybe Cycles
, cycles_accepted :: Cycles
, cycles_minted :: Cycles
, balance :: Cycles
, needs_to_respond :: NeedsToRespond
, response :: Maybe Response
Expand All @@ -199,6 +201,7 @@ initialExecutionState inst stableMem env needs_to_respond ctxt = ExecutionState
, cycles_available = Nothing
, balance = env_balance env
, cycles_accepted = 0
, cycles_minted = 0
, needs_to_respond
, response = Nothing
, reply_data = mempty
Expand Down Expand Up @@ -276,6 +279,10 @@ addAccepted :: ESRef s -> Cycles -> HostM s ()
addAccepted esref f = modES esref $ \es ->
es { cycles_accepted = cycles_accepted es + f }

addMinted :: ESRef s -> Cycles -> HostM s ()
addMinted esref f = modES esref $ \es ->
es { cycles_minted = cycles_minted es + f }

subtractBalance :: ESRef s -> Cycles -> HostM s ()
subtractBalance esref f = do
current_balance <- getsES esref balance
Expand Down Expand Up @@ -349,11 +356,13 @@ systemAPI esref =
, toImport' "ic0" "accept_message" [EXC_F] accept_message
, toImport' "ic0" "time" star get_time
, toImport' "ic0" "performance_counter" star performance_counter
, toImport' "ic0" "global_timer_set" [EXC_I, EXC_U, EXC_Ry, EXC_Rt, EXC_C, EXC_T] global_timer_set
, toImport' "ic0" "global_timer_set" [EXC_I, EXC_G, EXC_U, EXC_Ry, EXC_Rt, EXC_C, EXC_T] global_timer_set
, toImport' "ic0" "canister_version" star get_canister_version

, toImport' "ic0" "debug_print" star debug_print
, toImport' "ic0" "trap" star explicit_trap

, toImport' "ic0" "mint_cycles" [EXC_U, EXC_Ry, EXC_Rt, EXC_T] mint_cycles
]
where
-- Utilities
Expand Down Expand Up @@ -738,6 +747,15 @@ systemAPI esref =
let msg = BSU.toString bytes
throwError $ "canister trapped explicitly: " ++ msg

mint_cycles :: Word64 -> HostM s Word64
mint_cycles amount = do
self <- gets (env_self . env)
let cmc = wordToId 4
unless (self == cmc) $ throwError $ "ic0.mint_cycles can only be executed on Cycles Minting Canister: " ++ show self ++ " != " ++ show cmc
addBalance esref $ fromIntegral amount
addMinted esref $ fromIntegral amount
return amount

-- The state of an instance, consisting of
-- * the underlying Wasm state,
-- * additional remembered information like the CanisterId
Expand Down Expand Up @@ -912,7 +930,7 @@ rawUpdate method caller env needs_to_respond cycles_available dat (ImpState esre
case result of
Left err -> return $ Trap err
Right (_, es') -> return $ Return
( CallActions (calls es') (cycles_accepted es') (response es')
( CallActions (calls es') (cycles_accepted es') (cycles_minted es') (response es')
, canisterActions es'
)

Expand Down Expand Up @@ -940,7 +958,7 @@ rawCallback callback env needs_to_respond cycles_available res refund (ImpState
case result of
Left err -> return $ Trap err
Right (_, es') -> return $ Return
( CallActions (calls es') (cycles_accepted es') (response es')
( CallActions (calls es') (cycles_accepted es') (cycles_minted es') (response es')
, canisterActions es'
)

Expand Down
6 changes: 6 additions & 0 deletions src/IC/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ cDEFAULT_PROVISIONAL_CYCLES_BALANCE = 100_000_000_000_000

-- Subnets

canister_ids_per_subnet :: W.Word64
canister_ids_per_subnet = 1_048_576

nth_canister_range :: W.Word64 -> (W.Word64, W.Word64)
nth_canister_range n = (n * canister_ids_per_subnet, (n + 1) * canister_ids_per_subnet - 1)

-- reference_subnet_size is used for scaling cycle cost
-- and must never be set to zero!
reference_subnet_size :: W.Word64
Expand Down
2 changes: 1 addition & 1 deletion src/IC/Id/Forms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mkOpaqueId b =
b <> BS.singleton 1 <> BS.singleton 1

isOpaqueId :: Blob -> Bool
isOpaqueId b = BS.drop (BS.length b - 1) b == BS.singleton 1
isOpaqueId b = BS.drop (BS.length b - 2) b == BS.singleton 1 <> BS.singleton 1

mkSelfAuthenticatingId :: Blob -> Blob
mkSelfAuthenticatingId pubkey =
Expand Down
18 changes: 16 additions & 2 deletions src/IC/Id/Fresh.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IC.Id.Fresh where

import IC.Types
import IC.Id.Forms
import IC.Id.Forms hiding (Blob)

import Data.ByteString.Builder
import Data.Word
Expand All @@ -13,5 +13,19 @@ freshId ranges ids =
[] -> Nothing
(x:_) -> Just x

wordToId' :: Word64 -> Blob
wordToId' = mkOpaqueId . toLazyByteString . word64BE

wordToId :: Word64 -> EntityId
wordToId = EntityId . mkOpaqueId . toLazyByteString . word64BE
wordToId = EntityId . wordToId'

checkCanisterIdInRanges' :: [(Blob, Blob)] -> Blob -> Bool
checkCanisterIdInRanges' ranges cid = any (\(a, b) -> a <= cid && cid <= b) ranges

checkCanisterIdInRanges :: [(Word64, Word64)] -> CanisterId -> Bool
checkCanisterIdInRanges ranges cid = checkCanisterIdInRanges' (map (\(a, b) -> (wordToId' a, wordToId' b)) ranges) (rawEntityId cid)

isRootTestSubnet :: TestSubnetConfig -> Bool
isRootTestSubnet (_, _, _, ranges) = checkCanisterIdInRanges ranges nns_canister_id
where
nns_canister_id = wordToId 0
Loading

0 comments on commit 549cf38

Please sign in to comment.