Skip to content

Commit

Permalink
Merge branch 'develop' into feat/faster-inv-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcnelson authored Mar 15, 2022
2 parents 4ea7c99 + 443f248 commit 30890c6
Show file tree
Hide file tree
Showing 25 changed files with 360 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ tests (#2989).
key in the cost estimator. (#2984)
- Fixed a few prometheus metrics to be more accurate compared to `/v2` endpoints
when polling data (#2987)
- Fixed an error message from the type-checker that shows up when the type of a
parameter refers to a trait defined in the same contract (#3064).

## [2.05.0.0.0]

Expand Down
2 changes: 2 additions & 0 deletions clarity/src/vm/analysis/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub enum CheckErrors {
UnknownFunction(String),

// traits
NoSuchTrait(String, String),
TraitReferenceUnknown(String),
TraitMethodUnknown(String, String),
ExpectedTraitIdentifier,
Expand Down Expand Up @@ -393,6 +394,7 @@ impl DiagnosableError for CheckErrors {
CheckErrors::DefineNFTBadSignature => format!("(define-asset ...) expects an asset name and an asset identifier type signature as arguments"),
CheckErrors::NoSuchNFT(asset_name) => format!("tried to use asset function with a undefined asset ('{}')", asset_name),
CheckErrors::NoSuchFT(asset_name) => format!("tried to use token function with a undefined token ('{}')", asset_name),
CheckErrors::NoSuchTrait(contract_name, trait_name) => format!("use of unresolved trait {}.{}", contract_name, trait_name),
CheckErrors::TraitReferenceUnknown(trait_name) => format!("use of undeclared trait <{}>", trait_name),
CheckErrors::TraitMethodUnknown(trait_name, func_name) => format!("method '{}' unspecified in trait <{}>", func_name, trait_name),
CheckErrors::ImportTraitBadSignature => format!("(use-trait ...) expects a trait name and a trait identifier"),
Expand Down
35 changes: 35 additions & 0 deletions clarity/src/vm/analysis/trait_checker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,3 +1288,38 @@ fn test_return_trait_with_contract_of_wrapped_in_let() {
})
.unwrap();
}

#[test]
fn test_trait_contract_not_found() {
let trait_contract_src = "(define-trait my-trait
((hello (int) (response uint uint)))
)
(define-private (pass-trait (a <my-trait>))
(print a)
)
(define-public (call-it)
(ok (pass-trait .impl-contract))
)";
let impl_contract_src = "(define-public (hello (a int))
(ok u0)
)";

let trait_contract_id = QualifiedContractIdentifier::local("trait-contract").unwrap();
let impl_contract_id = QualifiedContractIdentifier::local("impl-contract").unwrap();

let mut impl_contract = parse(&impl_contract_id, impl_contract_src).unwrap();
let mut trait_contract = parse(&trait_contract_id, trait_contract_src).unwrap();
let mut marf = MemoryBackingStore::new();
let mut db = marf.as_analysis_db();

let err = db
.execute(|db| {
type_check(&impl_contract_id, &mut impl_contract, db, true)?;
type_check(&trait_contract_id, &mut trait_contract, db, true)
})
.unwrap_err();
match err.err {
CheckErrors::NoSuchContract(contract) => assert!(contract.ends_with(".trait-contract")),
_ => panic!("{:?}", err),
}
}
9 changes: 7 additions & 2 deletions clarity/src/vm/analysis/type_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,16 @@ impl<'a, 'b> TypeChecker<'a, 'b> {
let contract_defining_trait = self
.db
.load_contract(&trait_identifier.contract_identifier)
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
.ok_or(CheckErrors::NoSuchContract(
trait_identifier.contract_identifier.to_string(),
))?;

let trait_definition = contract_defining_trait
.get_defined_trait(&trait_identifier.name)
.ok_or(CheckErrors::NoSuchContract(contract_identifier.to_string()))?;
.ok_or(CheckErrors::NoSuchTrait(
trait_identifier.contract_identifier.to_string(),
trait_identifier.name.to_string(),
))?;

contract_to_check.check_trait_compliance(trait_identifier, trait_definition)?;
return Ok(expected_type.clone());
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions contrib/init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sample configuration files for:

```
systemd: stacks.service
SysVinit: stacks.init
MacOS: org.stacks.stacks-blockchain.plist
```

have been made available to assist packagers in creating node packages here.

See [docs/init.md](../../docs/init.md) for more information.
33 changes: 33 additions & 0 deletions contrib/init/org.stacks.stacks-blockchain.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.stacks.stacks-blockchain</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/stacks-node</string>
<string>start</string>
<string>--config=/etc/stacks-blockchain/Config.toml</string>
</array>

<key>ProcessType</key>
<integer>Standard</integer>

<key>StandardErrorPath</key>
<string>/tmp/stacks-blockchain.log</string>

<key>StandardOutPath</key>
<string>/tmp/stacks-blockchain.log</string>

<key>RunAtLoad</key>
<false/>

<key>ExitTimeOut</key>
<integer>60</integer>

<key>KeepAlive</key>
<false/>

</dict>
</plist>
113 changes: 113 additions & 0 deletions contrib/init/stacks.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash
# # Modelled after https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.init
#
# Stacks Blockchain
#
#
# chkconfig: 345 80 20
# description: stacks-blockchain
# processname: stacks-node
#
### BEGIN INIT INFO
# Provides: stacks-blockchain
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Stacks Blockchain
# Description: Stacks Blockchain
### END INIT INFO

# Source function library.
. /etc/init.d/functions

# you can override defaults in /etc/sysconfig/stacks-blockchain, see below
if [ -f /etc/sysconfig/stacks-blockchain ]; then
. /etc/sysconfig/stacks-blockchain
fi

RETVAL=0

prog=stacks-node
# you can override the lockfile via STACKS_BLOCKCHAIN_LOCKFILE in /etc/sysconfig/stacks-blockchain
lockfile=${STACKS_BLOCKCHAIN_LOCKFILE-/var/lock/subsys/stacks-blockchain}

# stacks-blockchain defaults to /usr/local/bin/stacks-node, override with STACKS_BLOCKCHAIN_BIN
stacks_bin=${STACKS_BLOCKCHAIN_BIN-/usr/local/bin/stacks-node}

# stacks-blockchain path to config toml, override with STACKS_BLOCKCHAIN_CONFIG
stacks_config=${STACKS_BLOCKCHAIN_CONFIG-/etc/stacks-blockchain/Config.toml}

# stacks-blockchain log file default to /var/log/stacks-blockchain.log, override with STACKS_BLOCKCHAIN_LOG
stacks_log=${STACKS_BLOCKCHAIN_LOG-/stacks-blockchain/output.log}
# Note: no logrotate is provided, you're encouraged to set something up like the following logrotate file:
# cat <<EOF> /etc/logrotate.d/stacks-blockchain
# /stacks-blockchain/output.log
# {
# missingok
# daily
# copytruncate
# rotate 7
# }
# EOF


start() {
if [ ! -f "$stacks_config" ];then
echo -n "Missing config file: $stacks_config "
return 1
fi
echo -n $"Starting $prog: "
$stacks_bin start --config="$stacks_config" > "$stacks_log" 2>&1 &
RETVAL=$?
[ $RETVAL -eq 0 ] && touch "$lockfile"
echo
return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -INT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f "$lockfile"
return $RETVAL
}

restart() {
stop
start
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 1
$1
;;
stop)
rh_status_q || exit 1
$1
;;
status)
rh_status
;;
restart)
$1
;;
*)
echo "Usage: service $prog {start|stop|status|restart}"
exit 2
;;
esac

exit $?
62 changes: 62 additions & 0 deletions contrib/init/stacks.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# # Modeled after https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service

[Unit]
Description=Stacks Blockchain
# https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
After=network-online.target
Wants=network-online.target

ConditionFileIsExecutable=/usr/local/bin/stacks-node
ConditionPathExists=/etc/stacks-blockchain/Config.toml
ConditionPathIsDirectory=/stacks-blockchain

[Service]
#ExecStart=/bin/sh -c "/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml >> /stacks-blockchain/output.log 2>&1"
ExecStart=/bin/sh -c "/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml"
ExecStartPost=/bin/sh -c "umask 022; sleep 2 && pgrep -f \"/usr/local/bin/stacks-node start --config=/etc/stacks-blockchain/Config.toml\" > /run/stacks-blockchain/stacks-blockchain.pid"
ExecStopPost=/bin/sh -c "if [ -f \"/run/stacks-blockchain/stacks-blockchain.pid\" ]; then rm -f /run/stacks-blockchain/stacks-blockchain.pid; fi"

# Make sure the config directory is readable by the service user
PermissionsStartOnly=true
#ExecStartPre=/bin/chgrp stacks /etc/stacks-blockchain/

# Process management
####################
Type=simple
PIDFile=/run/stacks-blockchain/stacks-blockchain.pid
Restart=no
TimeoutStopSec=600
KillSignal=SIGTERM

# Directory creation and permissions
####################################
# Run as stacks:stacks
User=stacks
Group=stacks

# /run/stacks-blockchain
RuntimeDirectory=stacks-blockchain
RuntimeDirectoryMode=0710

# Hardening measures
####################

# Provide a private /tmp and /var/tmp.
PrivateTmp=true

# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full

# Deny access to /home, /root and /run/user
ProtectHome=true

# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true

# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true

[Install]
WantedBy=multi-user.target
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 30890c6

Please sign in to comment.