Skip to content

Commit f989548

Browse files
authored
Merge pull request #23 from kunta-labs/development
Development
2 parents b66ae62 + 3561fd5 commit f989548

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

core/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ create_directories:
5252
build:
5353
cargo build --verbose;
5454
save:
55-
git add * ; git commit -am ${M} -v ; git push origin master:development -v
55+
git add * -v; git commit -am ${M} -v ; git push origin master:development -v
5656
get:
5757
git fetch ; git pull origin master;
5858
rms:
@@ -124,7 +124,19 @@ rac: # run all containers
124124
docker run -d -p 8081:8081 kuntalabs/africaos:latest ./core node-name="alices node" node-id=1 port=8081 peers=docker.for.mac.host.internal:8082,docker.for.mac.host.internal:8083 ip=docker.for.mac.host.internal:8081
125125
docker run -d -p 8082:8082 kuntalabs/africaos:latest ./core node-name="bob's node" node-id=2 port=8082 peers=docker.for.mac.host.internal:8081,docker.for.mac.host.internal:8083 ip=docker.for.mac.host.internal:8082
126126
docker run -d -p 8083:8083 kuntalabs/africaos:latest ./core node-name="cici's node" node-id=3 port=8083 peers=docker.for.mac.host.internal:8082,docker.for.mac.host.internal:8081 ip=docker.for.mac.host.internal:8083
127-
racl: # run all containers
127+
racl: # run all containers local
128128
docker run -d -p 8081:8081 aos:latest ./core node-name="alices node" node-id=1 port=8081 peers=docker.for.mac.host.internal:8082,docker.for.mac.host.internal:8083 ip=docker.for.mac.host.internal:8081
129129
docker run -d -p 8082:8082 aos:latest ./core node-name="bob's node" node-id=2 port=8082 peers=docker.for.mac.host.internal:8081,docker.for.mac.host.internal:8083 ip=docker.for.mac.host.internal:8082
130130
docker run -d -p 8083:8083 aos:latest ./core node-name="cici's node" node-id=3 port=8083 peers=docker.for.mac.host.internal:8082,docker.for.mac.host.internal:8081 ip=docker.for.mac.host.internal:8083
131+
stress_aws:
132+
while true; do make stress_a_aws; sleep 60 ; make stress_b_aws; sleep 60 ; make stress_c_aws; sleep 60 ; done
133+
stress_a_aws:
134+
curl -d 'TESTSTRING' --header "Origin: ${ALICE}:8081" --header "User-Agent: 100,200,test_string" ${ALICE}:8081/transaction/submit/output ;
135+
stress_b_aws:
136+
curl -d 'TESTSTRING' --header "Origin: ${BOB}:8082" --header "User-Agent: 100,200,test_string" ${BOB}:8082/transaction/submit/output ;
137+
stress_c_aws:
138+
curl -d 'TESTSTRING' --header "Origin: ${CICI}:8083" --header "User-Agent: 100,200,test_string" ${CICI}:8083/transaction/submit/output ;
139+
aws_docker_commands:
140+
echo "docker run -d -p 8081:8081 kuntalabs/africaos:latest ./core node-name='alices node' node-id=1 port=8081 peers=${BOB}:8082,${CICI}:8083 ip=${ALICE}:8081"
141+
echo "docker run -d -p 8082:8082 kuntalabs/africaos:latest ./core node-name='bobs node' node-id=2 port=8082 peers=${ALICE}:8081,${CICI}:8083 ip=${BOB}:8082"
142+
echo "docker run -d -p 8083:8083 kuntalabs/africaos:latest ./core node-name='cicis node' node-id=3 port=8083 peers=${BOB}:8082, ${ALICE}:8081 ip=${CICI}:8083"

core/block/src/lib.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ impl ReadBlockFromDB for DB {
137137
} else {
138138
// TODO: dont calculate number of blocks by length in block index
139139
//let mut amount_of_blocks: i64 = all_blocks.len() as i64;
140-
match Block::get_next_block_id() {
140+
//TODO: invoke get_next_block_id_from_index() instead
141+
//match Block::get_next_block_id() {
142+
match Block::get_next_block_id_from_index() {
141143
Some(block_id) => {
142-
println!("get_latest_block_id, Block::get_next_block_id() is SOME");
144+
println!("get_latest_block_id, Block::get_next_block_id(), get_next_block_id_from_index() is SOME");
143145
Some(block_id)
144146
},
145147
None => {
@@ -221,6 +223,7 @@ impl ReadBlockFromDB for DB {
221223
pub trait BlockIDGenerator {
222224
fn parse_filename_for_block_id(filename: &str) -> Option<i64>;
223225
fn get_next_block_id() -> Option<i64>;
226+
fn get_next_block_id_from_index() -> Option<i64>;
224227
}
225228

226229
impl BlockIDGenerator for Block {
@@ -250,6 +253,7 @@ impl BlockIDGenerator for Block {
250253
/*
251254
@name get_next_block_id
252255
@desc generate the next block_id from all blocks on disk
256+
@deprecated due to counting files, instead of accessing index
253257
*/
254258
fn get_next_block_id() -> Option<i64> {
255259
//read all directories
@@ -258,7 +262,7 @@ impl BlockIDGenerator for Block {
258262
let mut highest_block_index: i64 = -1;
259263
//iterate over all proposal files
260264
while let Some(v) = iter.next(){
261-
println!("Filename Iter: {}", v);
265+
//println!("Filename Iter: {}", v);
262266
//parse file name for proposal id
263267
let filename_split_vector = v.split("/").collect::<Vec<_>>();
264268
let last_split_section: &str = filename_split_vector[filename_split_vector.len() - 1];
@@ -282,6 +286,35 @@ impl BlockIDGenerator for Block {
282286

283287
}
284288
}
289+
290+
/*
291+
@name get_next_block_id_from_index
292+
@desc generate next block id from index
293+
*/
294+
fn get_next_block_id_from_index() -> Option<i64> {
295+
let parsed_option: Option<JsonValue> = DB::get_block_index_as_json();
296+
match parsed_option {
297+
Some(mut block_index) => {
298+
299+
let blocks_iter = &block_index.clone()["blocks"];
300+
let last_block_option = blocks_iter.entries().last().clone();
301+
match last_block_option {
302+
Some(last_block) => {
303+
let last_block_json = last_block.1;
304+
305+
// TODO: error handling
306+
Some(last_block_json["block_id"].as_i64().unwrap())
307+
308+
},
309+
None => {
310+
None
311+
}
312+
}
313+
314+
},
315+
None => None
316+
}
317+
}
285318
}
286319

287320

core/proposal/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/proposal/src/lib.rs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,11 @@ impl ReadProposalFromDB for DB {
498498
let proposal_index_option: Option<JsonValue> = Self::get_proposal_index_as_json();
499499
match proposal_index_option {
500500
Some(proposal_index) => {
501-
let next_proposal_id_option: Option<i32> = Proposal::get_next_proposal_id();
501+
502+
//TODO: invoke get_next_proposal_id_from_index() instead
503+
//let next_proposal_id_option: Option<i32> = Proposal::get_next_proposal_id();
504+
let next_proposal_id_option: Option<i32> = Proposal::get_next_proposal_id_from_index();
505+
502506
match next_proposal_id_option {
503507
Some(next_proposal_id) => {
504508
let mut all_proposals_vector: Vec<Proposal> = Vec::new();
@@ -778,7 +782,9 @@ impl NewProposal for Proposal {
778782
fn create(request_origin: String) -> Option<Proposal> {
779783
println!("Creating New Proposal...");
780784
//TODO: determine proposal ID
781-
let new_proposal_id:i32 = match Self::get_next_proposal_id(){
785+
//TODO: invoke get_next_proposal_id_from_index() instead
786+
//let new_proposal_id:i32 = match Self::get_next_proposal_id(){
787+
let new_proposal_id:i32 = match Self::get_next_proposal_id_from_index(){
782788
Some(pid) => pid,
783789
None => -1
784790
};
@@ -826,6 +832,7 @@ impl NewProposal for Proposal {
826832
trait ProposalIDGenerator {
827833
fn parse_filename_for_proposal_id(filename: &str) -> Option<i32>;
828834
fn get_next_proposal_id() -> Option<i32>;
835+
fn get_next_proposal_id_from_index() -> Option<i32>;
829836
}
830837

831838
impl ProposalIDGenerator for Proposal {
@@ -855,6 +862,7 @@ impl ProposalIDGenerator for Proposal {
855862
/*
856863
@name get_next_proposal_id
857864
@desc generate the next proposal_id from all proposals on disk
865+
@deprecated due to counting files, instead of accessing index
858866
*/
859867
fn get_next_proposal_id() -> Option<i32> {
860868
//read all directories
@@ -863,7 +871,7 @@ impl ProposalIDGenerator for Proposal {
863871
let mut highest_proposal_index: i32 = -1;
864872
//iterate over all proposal files
865873
while let Some(v) = iter.next(){
866-
println!("Filename Iter: {}", v);
874+
//println!("Filename Iter: {}", v);
867875
//parse file name for proposal id
868876
let filename_split_vector = v.split("/").collect::<Vec<_>>();
869877
let last_split_section: &str = filename_split_vector[filename_split_vector.len() - 1];
@@ -887,6 +895,36 @@ impl ProposalIDGenerator for Proposal {
887895

888896
}
889897
}
898+
899+
/*
900+
@name get_next_proposal_id_from_index
901+
@desc determine next proposal id from index
902+
*/
903+
fn get_next_proposal_id_from_index() -> Option<i32> {
904+
let parsed_option: Option<JsonValue> = DB::get_proposal_index_as_json();
905+
match parsed_option {
906+
Some(mut proposal_index) => {
907+
908+
let proposals_iter = &proposal_index.clone()["proposals"];
909+
let last_proposal_option = proposals_iter.entries().last().clone();
910+
match last_proposal_option {
911+
Some(last_proposal) => {
912+
let last_proposal_json = last_proposal.1;
913+
914+
// TODO: error handling
915+
Some(last_proposal_json["proposal_id"].as_i32().unwrap())
916+
917+
},
918+
None => {
919+
None
920+
}
921+
}
922+
923+
},
924+
None => None
925+
}
926+
927+
}
890928
}
891929

892930
#[derive(Clone,Debug,PartialEq)]
@@ -988,10 +1026,12 @@ impl ProposalValidator for Proposal {
9881026
//let current_block_id: Option<i64> = Block::get_latest_block_id();
9891027

9901028
//TODO: this is better than get_latest_block_id, since this counds block files instead of index length
991-
let current_block_id: Option<i64> = Block::get_next_block_id();
1029+
//TODO: invoke get_next_block_id_from_index() instead
1030+
//let current_block_id: Option<i64> = Block::get_next_block_id();
1031+
let current_block_id: Option<i64> = Block::get_next_block_id_from_index();
9921032

9931033
let current_block_id_result: i64 = match current_block_id {
994-
Some(block_id) => {
1034+
Some(block_id) => {
9951035
println!("validate_proposal(), current_block_id, block_id: {}", block_id);
9961036
// was just block_id, but substracting one since calling current_block_id
9971037
// block_id

0 commit comments

Comments
 (0)