Commit f42e9d12 authored by Tezos's avatar Tezos Committed by Arthur B.

First public release

parents
/tezos-node
/tezos-protocol-compiler
/tezos-client
/src/.depend
/src/node/updater/environment_gen
/src/node/updater/proto_environment.mli
/src/compiler/embedded_cmis.ml
/src/proto/**/_tzbuild
/src/proto/register_client_*.ml
/src/client/embedded/**/_tzbuild
/src/client/embedded/demo/.depend
/src/client/embedded/bootstrap/.depend
/src/client/embedded/bootstrap/concrete_lexer.ml
/src/client/embedded/bootstrap/concrete_parser.ml
/src/client/embedded/bootstrap/concrete_parser.mli
/test/.depend
/test/test-store
/test/test-state
/test/test-context
/test/test-basic
/test/LOG
*~
\#*\#
*.[oa]
*.so
*~
*.cm[iaoxt]
*.cmti
*.cmxa
*.cmxs
*.mli.deps
*.ml.deps
*.rej
*.orig
\ No newline at end of file
variables:
ocaml_image: alpine_ocaml-4.03.0
build_image_name: ocp_tezos_build
build_image_id: ${CI_BUILD_REF}
build_image: ${build_image_name}:${ocaml_image}
image: ${build_image}_${build_image_id}
stages:
- build_deps
- build
- build_test
- test
- publish
- cleanup
build_deps:
stage: build_deps
image: ocp:docker
tags:
- docker_builder
script:
- ./scripts/create_docker_builder.sh
${build_image_name} ${ocaml_image} "_${build_image_id}"
build:
stage: build
tags:
- tezos_builder
script:
- make -j4
artifacts:
expire_in: 1 week
untracked: true
build:test:
stage: build_test
tags:
- tezos_builder
script:
- make -C test build-test -j4
dependencies:
- build
artifacts:
expire_in: 1 week
untracked: true
test:store:
stage: test
tags:
- tezos_builder
script:
- make -C test run-test-store
dependencies:
- build
- build:test
test:context:
stage: test
tags:
- tezos_builder
script:
- make -C test run-test-context
dependencies:
- build
- build:test
test:state:
stage: test
tags:
- tezos_builder
script:
- make -C test run-test-state
dependencies:
- build
- build:test
test:basic:
stage: test
tags:
- tezos_builder
script:
- make -C test run-test-basic
dependencies:
- build
- build:test
test:basic.sh:
stage: test
tags:
- tezos_builder
script:
- make -C test run-test-basic.sh
dependencies:
- build
- build:test
publish:expurge:
stage: publish
tags:
- tezos_builder
only:
- master@tezos/tezos
script:
- echo "${CI_KH}" > ~/.ssh/known_hosts
- echo "${CI_PK}" > ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
- rm -fr .git/refs/original
- git filter-branch --prune-empty --index-filter
'git rm -r --cached --ignore-unmatch
.gitlab-ci.yml
"docs/proof of stake.md"
src/client/embedded/bootstrap/mining/'
--env-filter
'export GIT_AUTHOR_NAME="Dynamic Ledger Solutions, Inc." ;
export GIT_AUTHOR_EMAIL="contact@tezos.com"'
HEAD
- git tag ${CI_BUILD_REF}_expurged
- git push git@gitlab.ocamlpro.com:${CI_PROJECT_PATH}.git
-f --tags HEAD:master-expurged
publish:github:
image: ocaml/opam:${ocaml_image}
stage: publish
tags:
- tezos_builder
only:
- master@tezos/tezos
when: manual
script:
- echo "${CI_KH}" > ~/.ssh/known_hosts
- echo "${CI_PK}" > ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
- git reset ${CI_BUILD_REF}_expurged
- git push git@github.com:OCamlPro/tezos.git
-f HEAD:master
cleanup:
stage: cleanup
image: ocp:docker
tags:
- docker_builder
script:
- docker tag ${build_image}_${build_image_id}
${build_image}_${CI_PROJECT_NAMESPACE}_${CI_BUILD_REF_NAME}
- docker rmi ${build_image}_${build_image_id}
when: always
match_clause = 4
all:
${MAKE} -C src all
clean:
${MAKE} -C src clean
.PHONY:test
test:
${MAKE} -C test
build_deps:
@./scripts/install_build_deps.sh all
TEZOS
=====
To compile:
```
make build-deps
make
```
=========
To run a single instance :
```
./tezos-node
```
All useful data are stored in `${HOME}/.tezos-node`.
To run a test instance, without connecting to the gossup network :
```
./tezos-node -sandbox /path/to/a/custom/data/dir
```
Useful data will be stored in the directory `/path/to/a/custom/data/dir`
instead of `${HOME}/.tezos-node`.
=========
To create other instances on the same machine, it is possible to
duplicate and edit `${HOME}/.tezos/config` while taking care not to
share paths for accessing the database or any other data file
(cf. options `db.store` ; `db.context` ; `net.peers` and `protocol.dir`).
Another possibility is to let Tezos generate a config file by specifying
options on the command line. For instance, if `${DIR}/config` does not
exist, the following command will generate it and replace the default values
with the values from the command line arguments:
```
./tezos-node -base-dir ${DIR} -net-port 2023 -net-addr 127.0.0.1
```
The Tezos server has a built-in mechanism to discover peers on the local net
(using UDP packets broadcasted on port 7732)
If this mechanism isn't sufficient, one can provide Tezos with a list of
initial peers, either by editing the option `net.bootstrap.peers` in the
`config` file, or by specifying a command line parameter:
```
./tezos-node -base-dir ${DIR} -net-port 2023 -net-addr 127.0.0.1 \
-net-bootstrap-peers '[("127.0.0.1", 2021);("127.0.0.1", 2022)]'
```
If `${DIR}/config` exists, the command line options override those read
in the config file. Tezos never modifies the content of an existing
`${DIR}/config` file.
```
./tezos-node -config-file ${DIR}/config
```
# Tezos Code Tutorial
## Introduction
The purpose of this document is to help contributors get started with the Tezos
codebase. The code is organized in several layers in a way which largely reflects the philosophy of the project. It creates a very strict separation between the "node", which implements the network protocol described in the white paper and between the protocols themselves. Of course the seed protocol itself is a very important part of the Tezos project and it follows a similar organization. The economic protocol sits on top of a few layers of abstractions dealing primarily with storing and retrieving data from the current context.
## Overview of the source
This section presents a brief overview of the layout of the source files and their significance.
### node
The network shell
#### node/db
Persistent data structures used by the shell to store its state.
#### note/net
Connectivity for the gossip network and primitives to create RPC services
#### node/shell
The shell itself
#### node/updater
Manage on-the-fly updates to the protocol
### proto
This is where the protocols live
#### proto/environment
#### proto/current
### utils
### compiler
### client
### client/embedded
### Node, the network shell
### Storing the context
## Irmin
Tezos needs to store potentially different version of its context, corresponding to potentially different branches of the blockchain. This also implies the ability to roll back the changes made by any single block, and to make atomic changes to the structure on disk for eac block to avoid corruption.
To that extent, Tezos borrows from the MirageOS project a module called [Irmin](https://github.com/mirage/irmin "Irmin")
> Irmin is a library to persist and synchronize distributed data structures both on-disk and in-memory. It enables a style of programming very similar to the Git workflow, where distributed nodes fork, fetch, merge and push data between each other. The general idea is that you want every active node to get a local (partial) copy of a global database and always be very explicit about how and when data is shared and migrated.
Caveat: although Tezos **is** a distributed ledger, it does **not** rely on Irmin's distributed store capabilities. For our purposes we only use Irmin as a local storage. The git structure is particularly well suited to represent the versionning implicit in the state of a blockchain based ledger. In fact, the context of Tezos can be observed by running "git checkout" in the data directory.
## Netbits and Jsont
Netbits and Jsont are modules which allow for the typesafe serialization of OCaml objects in a binary format and in Json (respectively). Importantly, it does not make of the potentially brittle representation created by the compiler and access through the Obj.magic function. Serializers are created using a set of type constructors defined in a GADT.
## (MISC STUFF TO BE ORGANIZED IN THE DOCUMENT)
The "Main" module represents the fixed interface between the economic protocol and the shell.
A protocol consists of several .ml and .mli files and a file name TEZOS_PROTOCOL which lists the modules in order of inclusion for the compilation. Lower level modules sit below high level modules.
What are \\_repr modules?
These modules handle the low level representation of a type, in particular its serialization in Json and in binary format. A module based on this type will often exist on top of it and provide functionality around that type. This provides finely grained layers of encapsulation to mininize the visible interfaces.
This diff is collapsed.
#! /bin/sh
set -x
dir=$(mktemp -d)
cur_dir="$(dirname "$(readlink -f "$0")")"
image_name=${1:=tezos_build}
ocaml_version=${2:=alpine_ocaml-4.03.0}
image_version=$3
cp ${cur_dir}/install_build_deps.sh ${dir}
cp ${cur_dir}/../src/tezos-deps.opam ${dir}
cat > ${dir}/Dockerfile <<EOF
FROM ocaml/opam:${ocaml_version}
COPY install_build_deps.sh /tmp
COPY tezos-deps.opam /tmp/src/tezos-deps.opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh pin \
&& rm -fr ~/.opam/log/
USER root
ENV HOME /home/opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh depext \
&& rm -fr ~/.opam/log/
RUN apk add libsodium-dev
USER opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh install \
&& rm -fr ~/.opam/log/
EOF
docker build -t ${image_name}:${ocaml_version}${image_version} ${dir}
#! /bin/sh
OCAML_VERSION=4.03.0
if [ "$(ocaml -vnum)" != "${OCAML_VERSION}" ]; then
echo ;
echo " Unexpected compiler version ($(ocaml -vnum))";
echo " You should use ocaml-${OCAML_VERSION}.";
echo ;
exit 1;
fi
cmd=$1
if [ -z "$cmd" ] ; then cmd=all ; fi
case $cmd in
pin)
pin=yes
;;
depext)
depext=yes
;;
install)
install=yes
;;
all)
pin=yes
depext=yes
install=yes
;;
*)
echo "Unknown command '$cmd'."
echo "Usage: $0 [pin|depext|install|all]"
exit 1
esac
set -e
set -x
if [ ! -z "$pin" ] ; then
opam pin --yes remove --no-action --dev-repo ocplib-json-typed || true
opam pin --yes remove --no-action --dev-repo ocplib-resto || true
opam pin --yes add --no-action --dev-repo sodium
opam pin --yes add --no-action --dev-repo ocp-ocamlres
opam pin --yes add --no-action --dev-repo ocplib-resto
opam pin --yes add --no-action tezos-deps src
fi
if [ ! -z "$depext" ] ; then
opam list --installed depext || opam install depext
opam depext ${DEPEXTOPT} tezos-deps
fi
if [ ! -z "$install" ] ; then
if opam list --installed tezos-deps ; then
opam upgrade $(shell opam list -s --required-by tezos-deps)
else
opam install tezos-deps
fi
fi
S node/net
B node/net
S node/updater
B node/updater
S node/shell
B node/shell
S node/db
B node/db
S utils
B utils
S proto/environment
B proto/environment
S compiler
B compiler
S client
B client
FLG -open Result
FLG -w -30
FLG -w -40
PKG base64
PKG calendar
PKG cohttp
PKG compiler-libs.optcomp
PKG conduit
PKG config-file
PKG cryptokit
PKG cstruct
PKG dynlink
PKG ezjsonm
PKG git
PKG irmin
PKG lwt
PKG ocplib-endian
PKG ocplib-json-typed
PKG ocplib-ocamlres
PKG ocplib-resto.directory
PKG result
PKG sodium
PKG unix
PKG zarith
This diff is collapsed.
INCLUDES = \
$(patsubst %, -I %, $(SOURCE_DIRECTORIES)) \
$(patsubst %, -package %, $(PACKAGES)) \
$(patsubst %, -open %, $(OPENED_MODULES))
OCAMLFLAGS = \
-g -safe-string -bin-annot -w +27-30-40 -short-paths \
${INCLUDES} \
${EXTRA_OCAMLFLAGS}
OCAMLC = ocamlfind ocamlc
OCAMLOPT = ocamlfind ocamlopt
OCAMLMKTOP = ocamlfind ocamlmktop
OCAMLDEP = ocamlfind ocamldep
OCAMLRES = ocp-ocamlres
OCAMLLEX = ocamllex
MENHIR = menhir
REC
FLG -open Error_monad -open Hash -open Utils
S embedded
B embedded
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(* Tezos Command line interface - Local Storage for Configuration *)
open Lwt
open Cli_entries
module type Entity = sig
type t
val encoding : t Data_encoding.t
val of_source : string -> t Lwt.t
val to_source : t -> string Lwt.t
val name : string
end
module type Alias = sig
type t
val load : unit -> (Lwt_io.file_name * t) list Lwt.t
val find : Lwt_io.file_name -> t Lwt.t
val find_opt : Lwt_io.file_name -> t option Lwt.t
val rev_find : t -> Lwt_io.file_name option Lwt.t
val name : t -> string Lwt.t
val mem : Lwt_io.file_name -> bool Lwt.t
val add : Lwt_io.file_name -> t -> unit Lwt.t
val del : Lwt_io.file_name -> unit Lwt.t
val save : (Lwt_io.file_name * t) list -> unit Lwt.t
val to_source : t -> string Lwt.t
val alias_param :
?n:string ->
?desc:string ->
'a Cli_entries.params ->
(Lwt_io.file_name * t -> 'a) Cli_entries.params
val fresh_alias_param :
?n:string ->
?desc:string ->
'a Cli_entries.params -> (string -> 'a) Cli_entries.params
val source_param :
?n:string ->
?desc:string ->
'a Cli_entries.params -> (t -> 'a) Cli_entries.params
end
module Alias = functor (Entity : Entity) -> struct
let encoding =
let open Data_encoding in
list (obj2
(req "name" string)
(req "value" Entity.encoding))
let filename () =
Client_config.(base_dir#get // Entity.name ^ "s")
let load () =
let filename = filename () in
if not (Sys.file_exists filename) then return [] else
Data_encoding.Json.read_file filename >>= function
| None ->
error "couldn't to read the %s alias file" Entity.name
| Some json ->
match Data_encoding.Json.destruct encoding json with
| exception _ -> (* TODO print_error *)
error "didn't understand the %s alias file" Entity.name
| list ->
return list
let find_opt name =
load () >>= fun list ->
try return (Some (List.assoc name list))
with Not_found -> return None
let find name =
load () >>= fun list ->
try return (List.assoc name list)
with Not_found -> error "no %s alias named %s" Entity.name name
let rev_find v =
load () >>= fun list ->
try return (Some (List.find (fun (_, v') -> v = v') list |> fst))
with Not_found -> return None
let mem name =
load () >>= fun list ->
try
ignore (List.assoc name list) ;
Lwt.return true
with
| Not_found -> Lwt.return false
let save list =
catch
(fun () ->
let dirname = Client_config.base_dir#get in
(if not (Sys.file_exists dirname) then Utils.create_dir dirname
else return ()) >>= fun () ->
let filename = filename () in
let json = Data_encoding.Json.construct encoding list in
Data_encoding.Json.write_file filename json >>= function
| false -> fail (Failure "Json.write_file")
| true -> return ())
(fun exn ->
error "could not write the %s alias file: %s."
Entity.name (Printexc.to_string exn))
let add name value =
let keep = ref false in
load () >>= fun list ->
(if not Client_config.force#get then
Lwt_list.iter_s (fun (n, v) ->
if n = name && v = value then
(message "The %s alias %s already exists with the same value." Entity.name n ;
keep := true ;